← Hash Map

Pattern Recognition Drill

#24 — First non-repeating character

Easy Hash Maps

The Problem

Find the index of the first character that appears only once.

What approach would you use?

Think about it before scrolling down.

Key Signals

Hash Map

Pass 1: count frequencies. Pass 2: scan left-to-right, return first count==1. O(n).

Common Trap

Nested loops checking each character against all others is O(n²). Counter reduces to O(n).

← #23 #25 →