Well done! You turned repeated range totals into single subtractions, cut sorted searches down to a logarithmic number of steps, and chose between the two yourself in the mixed exercises and a mock interview. Now pick the problem where an index slipped by one or a loop refused to stop. Close your earlier code and solve it again with a fresh example.
Before you run the tests, state the invariant your code keeps. What does a prefix total at position i include? What does the remaining search interval promise about the answer? Then account for the work and extra storage, including any slices you create.
Next, try changing one constraint. Ask for the last position instead of the first, allow negative values in a range problem, or remove the sorted-input guarantee. Walk a small example through by hand and find the spot where your approach stops working.
When you’re ready for more, continue with the next course in the Coding Interview Practice learning path:
You’ll keep unfinished work in order and put ranges of time next to their neighbors. Happy practicing!