Back to the Problem
Count all frequencies first, then rescan for the first character with count 1.
Complexity: O(|S|)