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
|
410 Discussions
|
Please Login in order to post a comment
A O(strings+queries) solution in C++ using unordered_map where all operations used below are at O(1) according to to implementation document.
Hi! This was my attempt using Javascript. I think its o(n) time or o(n+q) technically. I could probably avoid storing them in arrays in the groupedStrings array in hindsight
Javascript solution
function matchingStrings(strings, queries) {
}
from collections import Counter
def matchingStrings(strings, queries): count = Counter(strings) results = [] for i in queries: if i in count: results.append(count[i]) else: results.append(0) return results
Kotlin Solution