Two Sum: One-Pass Hash Table Pattern
How to convert an O(n²) pairwise search into an O(n) linear scan by dynamically storing previously visited complements in a hash map.
At a glance
- Read time
- 5 min
- Key ideas
- 3
Visualizer
DomainDS
Knowledge / DS
Reusable problem-solving models, patterns, and carefully explained solutions.
start here

Showing 7 of 7 notes
How to convert an O(n²) pairwise search into an O(n) linear scan by dynamically storing previously visited complements in a hash map.
At a glance
Visualizer
Master the Last-In First-Out bracket validation pattern to guarantee well-nested code, arithmetic parsing, and balanced delimiters.
At a glance
Visualizer
How to reverse a singly linked list in-place using prev, curr, and next pointers with O(1) auxiliary space.
At a glance
Visualizer
Simulating recursion depth-first with an explicit stack to perform Left-Root-Right tree traversals.
At a glance
Visualizer
Explore network graph topologies tier-by-tier with a FIFO queue to guarantee shortest path discovery in unweighted graphs.
At a glance
Visualizer
Transform exponential tree recursion into linear O(n) tabulation by identifying overlapping subproblems and optimal substructure.
At a glance
Visualizer
Understanding how runtime call stacks allocate frames, suspend execution contexts, and unwind return values during recursion.
At a glance
Visualizer