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.
The following simple code worked for me. Since the length of name is less than 22, both time complexity and space complexity are O(n).
fromcollectionsimportdefaultdictdefcontacts(queries):# Write your code hererecord=defaultdict(int)ans=[]foroperation,nameinqueries:ifoperation=='add':foriinrange(len(name)):record[name[:i+1]]+=1else:ans.append(record[name])returnans
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Contacts
You are viewing a single comment's thread. Return to all comments →
The following simple code worked for me. Since the length of name is less than 22, both time complexity and space complexity are O(n).