Add once, subtract after.
transcript
A year of sales, minute by minute. Two hundred thousand range questions. Add up each range. Each question asks for a total between two minutes. How long does it take?
One question asks for days two to five. Nine, four, seven, three. The total is twenty three. The next question adds the same days again. Thousands of questions repeat the same work.
The ranges are wide. The total is thirty five billion additions. At one nanosecond each, that is thirty five seconds. The dashboard must answer at once. The first attempt is correct, and too slow.
Now keep running totals. Zero, five, seven, sixteen, twenty. Days two to five are marker six minus marker two. That is twenty three, in one subtraction. The list is built once, in one pass.
Adding each range costs thirty five billion steps. The prefix list costs seven hundred twenty five thousand. That is forty eight thousand times fewer. The build is counted too. It pays for itself after a few questions.
Work once, then subtract. Full breakdown in the lecture.