Find the longest unique string in the input list
I'm on my phone so can only give pointers. 


In the first loop you can use Map.get and switch on its value:

null: put True and add to wordsByLength
True: put False and remove from wordsByLength
False: do nothing



Map&lt;Integer, Set&lt;String&gt;&gt; wordsByLength tracks unique word sets, one per word length. It maps word length to a set of unique words. Whenever a new word appears in 1 above, add it to the set. When it is seen again for the first time in 2, remove it.

Next sort those entries by their keys (word length) in reverse and pull the first word from the first set.

Note that you may end up with ties of same-length words. The standard set will return an undefined "first" word. That may be okay.