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
|
246 Discussions
|
Please Login in order to post a comment
Average-case time complexity: Building the frequency map: O(n) Answering queries with hash lookups: O(q)
So the overall: O (n+q) on average
Java using a map to save the frequencies. This solution iterates each list only once.
Here is the typescript solution for the better time complexity and space complexity. The time complexity over here will be o(n + q). I have created a hash map for the faster retrival of the information: Python:
Here is the typescript solution for the better time complexity and space complexity. The time complexity over here will be o(n + q). I have created a hash map for the faster retrival of the information: Typescript: