Every exercise in this section had a slow answer that added up the same values over and over. The fast answer stored those totals once. Here’s the question that cracked each one:
| Exercise | The question that unlocked it |
|---|---|
| Answer Range Queries on Daily Signups | Which totals, computed once, turn every range into a single subtraction? |
| Find the Balance Point of a Route | If I know the whole route’s change and the change before this segment, what’s the change after it? |
| Count Stretches That Net to a Budget | Which earlier running total would make the stretch ending today net to the budget, and how often has it appeared? |
| Review an AI-Written Budget Checker | Which lines quietly assume every amount is positive, and what does 19.99 + 7.1 really equal? |
A quick self-check: think of the test that stayed red the longest for you. Which assumption in your code did it break? Interviewers often ask exactly that kind of question, and it’s a lot easier to answer once you’ve talked it through.
Want a second pair of eyes on your Prefix Sums work?
Prefix sums trade one pass of preparation for instant answers. The Binary Search section trades something else: it uses order you already have to skip most of the data.