← All Patterns

Pattern Recognition Drill

#24

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.

First non-repeating character

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 →