hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is the First Unique Character
A unique character appears exactly once. Hashing counts every letter first; a second left-to-right pass returns the first letter whose count is 1. Two linear passes beat scanning the string for every index.
leetcode. After counting, the second pass stops at l (count 1). e is skipped because it appears three times.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Count pass | O(n) |
| First-unique pass | O(n) |
| Space | O(Σ) |
Python implementation