We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is my code, before i read the discussions
The algorithm is:
1. i mapped the list to dict with the value is count, because dict won't have duplicate value. each of these strings key at least show 1 times.
2. Then, i try to find the the query by query_key in the mapped dict
string_dict = {}
results = []
for string in strings:
try:
if string_dict[string] is not None:
string_dict[string] += 1
except:
string_dict[string] = 1
for query in queries:
try:
results.append(string_dict[query])
except:
results.append(0)
pass
return results
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
woah, I'm amazed by this shortest solution
this is my code, before i read the discussions The algorithm is: 1. i mapped the list to dict with the value is count, because dict won't have duplicate value. each of these strings key at least show 1 times. 2. Then, i try to find the the query by query_key in the mapped dict