Stage 1 · Code
Arrays & Hashing
Sets & Deduplication
Use sets for O(1) membership checks and streak detection — the key to Longest Consecutive Sequence.
6 min readLeetCode Patterns for InterviewsCode
The Pattern
A set (map with only keys in Go) answers 'does this value exist?' in O(1). For consecutive-sequence type problems, load everything into a set, then only start counting streaks at the beginning of each streak (n-1 not in the set).
Set Representation as Hash Map
[0]
200
true
[1]
1
true
[2]
2
true
[3]
3
true
[4]
100
true
4
true
[5]
[6]
[7]
Goset-pattern-in-go.go
30 linesLn 1, Col 1Go
The key insight: checking set[n-1] ensures we only process the start of each consecutive sequence, giving O(n) total despite nested loops.
Problems
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.