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.
Best you can do with map-based is O((n+q)*logN). Think about HashMap performance when all strings have same hashcodes, your solution is O(n*q) as well. Only in java8 they introduced "treemap inside hashmap" for equi-hash comparable objects.
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
Best you can do with map-based is O((n+q)*logN). Think about HashMap performance when all strings have same hashcodes, your solution is O(n*q) as well. Only in java8 they introduced "treemap inside hashmap" for equi-hash comparable objects.
Here is reference to a 3-liner for hashmap solution in java8, maybe you'll like it https://www.hackerrank.com/challenges/sparse-arrays/forum/comments/304466