You are viewing a single comment's thread. Return to all comments →
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.
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
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.