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