First Unique Character in a String

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: First Unique Character in a String

Approach

First pass counts character frequencies. Second pass returns the first index whose character appears exactly once.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Frequency Count

Why It Works

Counting first guarantees we know global uniqueness before selecting the earliest valid position.

Updated Feb 2026