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.
- Sparse Arrays
- Discussions
Sparse Arrays
Sparse Arrays
Sort by
recency
|
351 Discussions
|
Please Login in order to post a comment
def matchingStrings(strings, queries): op=[] for q in queries: op.append(len(list(filter(lambda x: x==q,strings )))) return op
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); } }
Java 8 As it is not mention duplicates from the Queries collection, that might works as expected. Otherwise, pass the query as a Set to remove their duplicates.