hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Longest Consecutive Sequence
Numbers form a streak if they differ by 1, ignoring order and duplicates. Put every value in a set. Only start a streak from a number whose predecessor is missing — that is a true left edge. Then walk x+1, x+2, … while they exist.
100, 4, 200, 1, 3, 2. 1 has no predecessor, so the walk 1→2→3→4 yields length 4.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Build set | O(n) |
| Edge walks (total) | O(n) |
| Space | O(n) |
Python implementation