Showing Posts From

Subarrays

Hashing & Prefix Sum Patterns

Hashing & Prefix Sum Patterns

Week 20 notes: prefix sums plus a hash map is one of the combos I use most. O(1) range queries, counting subarrays with a target sum in one pass, 2-D prefix sums, and the difference array.

Two Pointers & Sliding Window (Advanced)

Two Pointers & Sliding Window (Advanced)

Week 19 notes: Phase 2 kicks off by pushing the two most reused array patterns to medium/hard. Variable windows with a shrink rule, the at-most/exactly counting trick, and multi-pointer partitioning.

Sliding Window Algorithm - Fixed & Variable Length

Sliding Window Algorithm - Fixed & Variable Length

Week 0 notes on the sliding window: when to use it, fixed vs variable windows, and how it turns a lot of subarray and substring problems from O(n^2) into O(n).