easyStringArrays & Hashing

First Unique Character in a String

easyTime: O(n)Space: O(1)

Signals to notice

find first character that appears exactly oncecharacter frequencypreserve order

Brute force first

For each character, count its occurrences in the entire string. Each character re-scans the whole string. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.

The key insight

Two passes: first count all frequencies in a hash map, then scan left-to-right to find the first character with count 1 (26 letters max). The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

What must stay true

The frequency map gives lookup for any character's count. The second left-to-right pass ensures we find the FIRST unique character by order of appearance. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Returning the least frequent character instead of the first unique one. Order matters — you must scan left-to-right in the original string. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Arrays & Hashing Pattern