⚠️ Prerequisites

This phase assumes you've completed Phase 2 (Data Structures) and Phase 3 (Algorithms). Especially: Arrays, Stacks, Trees, Recursion, and Binary Search. These techniques BUILD on those foundations.

Advanced Modules
6 Power Techniques
👈👉

Two Pointers

Two indices traversing an array simultaneously. Eliminates the need for nested loops in many problems.

Appears in: 3Sum, Container with Most Water, Trapping Rain Water, Remove Duplicates
🪟

Sliding Window

Maintain a window that grows/shrinks based on conditions. Turns O(n²) subarray problems into O(n).

Appears in: Longest Substring Without Repeating, Minimum Window Substring, Max Consecutive Ones
📉

Monotonic Stack

A stack that maintains increasing or decreasing order. Solves "next greater element" type problems in O(n).

Appears in: Next Greater Element, Largest Rectangle in Histogram, Daily Temperatures
🌲

Tries (Prefix Trees)

A tree where each path spells a word. O(m) lookup for any word. Essential for autocomplete and word search.

Appears in: Implement Trie, Word Search II, Design Add and Search Words

Bit Manipulation

Operations directly on binary representations. XOR, AND, OR, shifts. Surprisingly elegant solutions.

Appears in: Single Number, Counting Bits, Missing Number, Reverse Bits
🌿

Segment Trees & BIT

Range query and update in O(log n). Segment Tree for max/min/sum queries. Binary Indexed Tree for prefix sums.

Appears in: Range Sum Query, Count of Smaller Numbers After Self
Decision Guide
When to Use Which Technique
Technique
Use When Problem Has...
Example Problem
Two Pointers
Sorted array, pairs summing to target, removing duplicates in-place
3Sum, Remove Duplicates
Sliding Window
Contiguous subarray/substring with max/min/exact constraint
Min Window Substring
Monotonic Stack
"Next greater/smaller", "visible buildings", "histogram areas"
Largest Rectangle
Trie
Word prefix lookup, autocomplete, dictionary operations on strings
Word Search II
Bit Manipulation
Missing/duplicate in [1,n], single element among duplicates, power of 2
Single Number (XOR)
Segment Tree
Range queries + updates on array (sum, max, min) repeatedly
Range Sum Query Mutable
Pattern Radar
Trigger Words — hear this, think that

Problem setters telegraph the technique in their phrasing. Train yourself to react to the exact words:

"…longest/shortest contiguous subarray such that…"
Sliding Window — contiguous + a constraint is the signature. If it says subsequence instead, it's DP.
"…the next greater/previous smaller element…", "…can see the ocean…"
Monotonic Stack — any nearest-dominating-neighbor question, including spans and histogram areas.
"…sorted array…", "…pair/triplet that sums to…", "…in-place without extra space…"
Two Pointers — sorted order or a partition invariant makes inward scanning provably safe.
"…starts with…", "…autocomplete…", "…search many words in…"
Trie — prefix structure. Add "maximum XOR" to the list: that's a binary trie over bits.
"…every element appears twice except…", "…without using extra memory…", "…power of two…"
Bit Manipulation — XOR cancellation and n&(n−1) tricks live here.
"…answer range queries while the array changes…"
Segment Tree / BIT — updates + range aggregates. Static array? Plain prefix sums, don't overbuild.
← Phase 3: Algorithms Phase 5: LeetCode Hard →