-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparse_array.py
45 lines (31 loc) · 915 Bytes
/
sparse_array.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Sparse Array Problem on HackerRank
Problem Link: https://www.hackerrank.com/challenges/sparse-arrays/problem
Author: Shyam Kumar
"""
# Complete the matchingStrings function below.
def matchingStrings(strings, queries):
ans=[]
for q in queries:
count=0
for s in strings:
if s==q:
count+=1
ans.append(count)
return ans
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
strings_count = int(input())
strings = []
for _ in range(strings_count):
strings_item = input()
strings.append(strings_item)
queries_count = int(input())
queries = []
for _ in range(queries_count):
queries_item = input()
queries.append(queries_item)
res = matchingStrings(strings, queries)
fptr.write('\n'.join(map(str, res)))
fptr.write('\n')
fptr.close()