In the solution for streaming, if we instantiate the dict object by using accessOrder = true in the constructor, which means entries sort by access order, then we wouldn’t need the dict.remove(s) anymore right? We are already doing “Integer it = dict.get(s)” which means every time we encounter a word that is part of the query string set, we are enforcing an access from the LinkedHashMap. So the element is already at the front of the queue before we do dict.put.
Secondly, it’s better to move if (numStringsFromQueryStringsSeenSoFar == queryStrings.size()) inside if (dict.containsKey(s)) {
There’s no point of doing the check if the next word in the stream is not even in the hash map.