Pick the fix
Prices are sorted ascending, and adding prices[i] already passes the goal. What should the loop do?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Break: every later price is at least as big
Right: sorting turns one overshoot into a stop for the whole loop.
Ordering the input is what makes the stronger prune safe, and it often matters more than any micro-optimisation.
Why not the others?
- B Continue to the next price. Correct, but it checks prices that must also overshoot.
- C Return the current count as the final answer. Other branches higher in the tree may still find hits.