Water Bottles
Real-world version: Canteen Refills on the RidgeThe statement here is our own: the same inputs, outputs and technique.
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.
Examples
Example 1
- Input
- numBottles = 12, numExchange = 4
- Output
- 15
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
- Input
- numBottles = 6, numExchange = 100
- Output
- 6
Six containers never reach the 100 the counter asks for, so the only bottles emptied are the six carried in.
Example 3
- Input
- numBottles = 100, numExchange = 2
- Output
- 199
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.
Constraints
- 1 <= numBottles <= 100
- 2 <= numExchange <= 100
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def num_water_bottles(numBottles: int, numExchange: int) -> int:public int numWaterBottles(int numBottles, int numExchange)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's