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.
My solution using linkedHashmap,
Note: There is no edge case to this solution, not a good one.
I thought even if duplicates are given in "Queries" list, it should be ignored, apparaently not.
LinkedHashMap map = new LinkedHashMap<>();
for(String s : queries)
{
if(!map.containsKey(s))
{
map.put(s, 0);
}
}
for(String s : strings)
{
if(map.containsKey(s))
{
int curVal = map.get(s);
curVal = curVal+1;
map.put(s, curVal);
}
}
List<Integer> ans = new ArrayList<Integer>();
for(String s : queries)
{
ans.add(map.get(s));
}
return ans;
}
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 →
My solution using linkedHashmap, Note: There is no edge case to this solution, not a good one. I thought even if duplicates are given in "Queries" list, it should be ignored, apparaently not. LinkedHashMap map = new LinkedHashMap<>(); for(String s : queries) { if(!map.containsKey(s)) { map.put(s, 0); } }