Array Algorithms: Prefix Sums, Two Pointers & Sliding Window
Master foundational algorithmic patterns on arrays: static range queries via Prefix Sums, opposite-end and fast/slow Two Pointers, and dynamic Sliding Windows.
Array indexing and complexity analysis
Mastery of prefix sums, two-pointer boundary scans, variable sliding windows, and Kadane's maximum subarray invariant.
Read in order, or jump to what you need.
Every lesson builds on the one before it. Open any lesson to read the explanation, run the examples, and try the practice challenges.
- 07.01Prefix Sums, Difference Arrays & O(1) Range Queries4 min
Transform O(N) range queries into O(1) lookups. Master 1D and 2D prefix sums, subarray sum equals K with HashMaps, and difference arrays for range updates.
- 07.02The Two Pointers Pattern: Opposing Ends & Slow/Fast Collisions4 min
Master the two pointers technique. Contrast inward-converging pointers for sorted arrays (Two-Sum II, Container With Most Water) with fast/slow pointers for in-place array compaction.
- 07.03The Sliding Window Pattern: Fixed vs Dynamic Windows4 min
Master the sliding window pattern. Contrast Fixed-Size windows (maximum sum subarray of size K) with Dynamic-Size windows (longest substring without repeating characters).
- 07.04Maximum Subarray Invariants: Kadane's Algorithm and Circular Buffers4 min
Dissect dynamic programming invariants in continuous array problems, implementing Kadane's algorithm, tracking indices, and solving the maximum circular subarray problem.
Ready to move on?
Solve sliding window substring problems and circular maximum subarray problems in linear time.
Open the module self-check