Trains the technique from
LeetCode 1518Water BottlesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A ridge depot keeps hikers supplied with drinking water. You set out holding numBottles sealed bottles.
Emptying a sealed bottle leaves you with one used container, and you always keep your used containers. The depot will hand over one fresh sealed bottle in return for numExchange used containers, and you may go back to the counter as often as you like while you still hold that many used containers.
Return how many bottles you empty in total.
Example 1
Emptying the 12 sealed bottles leaves 12 containers, which trade for 3 sealed bottles. Emptying those brings the tally to 15 and leaves 3 containers, too few for another trade.
Example 2
Six containers never reach the 100 the counter asks for, so the only bottles emptied are the six carried in.
Example 3
Trips to the counter bring back 50, then 25, then 12 with one container held over, then 6, 3, 2 and 1, and the tally reaches 199.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def num_water_bottles(numBottles: int, numExchange: int) -> int:public int numWaterBottles(int numBottles, int numExchange)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.