Ice Cream Parlor

  • + 1 comment

    You move the left index if the total cost is less than your budget and the right index if it is too much.

    1 2 3 4 5

    Start with l=1, r=5. That's 6, which is too much. We therefore move the right pointer to 4, and discover a solution.

    I used this method, and I passed.