Two passes solve this: First pass: Count how many times each character appears. A dictionary works perfectly here.
Second pass: Go through the string in order, return the first character with count . Why two passes? You can't know if a character repeats until you've seen the whole string. The character 'a' might be unique after seeing half the string, but repeat in the second half. Counting first, then checking, gives you the complete picture before making a decision.