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.
{// Dictionary to store frequency of each string in the input listDictionary<string,int>stringFrequency=newDictionary<string,int>();// Populate the dictionary with the count of each string in the input listforeach(varstrinstrings){if(stringFrequency.ContainsKey(str)){stringFrequency[str]++;}else{stringFrequency[str]=1;}}// List to store the result for each queryList<int>results=newList<int>();// Check the frequency of each query in the dictionary and add to resultsforeach(varqueryinqueries){if(stringFrequency.ContainsKey(query)){results.Add(stringFrequency[query]);}else{results.Add(0);// If the query is not in the dictionary, add 0}}returnresults;}
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 →
C# Solution