-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSparseArrays.py
24 lines (22 loc) · 1009 Bytes
/
SparseArrays.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#https://www.hackerrank.com/challenges/sparse-arrays
#Given a file of strings determine how many times the first batch of strings appear in the second batch
import unittest
def sparseArray(strings1, strings2):
queries = []
queryCount = 0
strings1 = strings1.split()
strings2 = strings2.split()
for query in strings1:
for string in strings2:
if query == string:
queryCount += 1
queries.append(queryCount)
queryCount = 0
return queries
class Test(unittest.TestCase):
def test_sparseArray(self):
self.assertEqual(sparseArray("Hot the cat", "Hot chocolate, the delicious drink that warms you."), [1, 1, 0])
self.assertEqual(sparseArray("Then there but what", "Then who what where there when there why but Then how"), [2, 2, 1, 1])
self.assertEqual(sparseArray("aba jkl", "red blue aba non jkl jkl aba yellow"), [2, 2])
self.assertEqual(sparseArray("", "I would walk 500 miles"), [])
unittest.main()