SproutStackSproutStack home
Section checkpoint

Core Patterns

14 questions drawn from the 7 chapters in this section. If most land on the first try, you are ready for the next section. If not, the explanation after each answer says which idea to revisit.

Checkpoint

14 questions · first-try answers earn the most XP

1. A friend asks for the pair whose sum is closest to a target in an unsorted array. What should you tell them?
2. When is the two-pointer technique the wrong tool?
3. Why does a plain sliding window fail to find the shortest subarray whose sum is at least a target when the array can contain negative numbers?
4. Your sliding-window solution returns an off-by-one on the window bounds. What is the most common cause?
5. In frequency counting with a map, why do you usually scan the map afterwards rather than during the loop?
6. Why can a hash map's worst case degrade to O(n)?
7. Why does the sliding-window technique fail for counting subarrays that sum to k?
8. Prefix sums extend to 2D grids. What is the equivalent idea?
9. Why use `l + (r - l) // 2` instead of `(l + r) // 2`?
10. Why must the search move to `m + 1` or `m - 1` rather than `m`?
11. Why can an O(n) sort only be used with constraints?
12. What does "sort to unlock" mean as an interview heuristic?
13. Why does the maximum-product variant need to track both a maximum and a minimum?
14. What extra work is needed if the problem asks for the subarray rather than its sum?

What this checkpoint covers

Next section: Essential Data Structures