An O(n) solution with O(1) time to check the most recent unique character by using the ReversedIteratingLinkedHashSet I wrote, basically writing a knock off LinkedHashSet with iteration order reversed.