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.
defmatchingStrings(stringList,queries):# Write your code heresortedList=sorted(stringList)ans=[]idx=-1matchCount=0forqinqueries:idx=binary_search_bisect(sortedList,q)ifidx==-1:ans.append(matchCount)continueforiinrange(idx,len(sortedList)):ifsortedList[i]!=q:breakelse:matchCount=matchCount+1ans.append(matchCount)matchCount=0returnansdefbinary_search_bisect(sorted_list,target):i=bisect.bisect_left(sorted_list,target)ifi!=len(sorted_list)andsorted_list[i]==target:returnireturn-1
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 →
python solution