Medium
You are given two integers numBottles
and numExchange
.
numBottles
represents the number of full water bottles that you initially have.numExchange
empty bottles with one full water bottle. Then, increase numExchange
by one.⚠️ Note: You cannot exchange multiple batches of empty bottles for the same value of numExchange
.
For example, if numBottles == 3
and numExchange == 1
, you cannot exchange 3 empty water bottles for 3 full bottles.
Return the maximum number of water bottles you can drink.
Input:
numBottles = 13, numExchange = 6
Output:
15
Step-by-step table (Full / Empty / numExchange / cumulative drunk):
Step | Action | Full (after) | Empty (after) | numExchange (used → new / or current) | Drunk (cumulative) |
---|---|---|---|---|---|
0 | Start | 13 | 0 | 6 | 0 |
1 | Drink 13 | 0 | 13 | 6 | 13 |
2 | Exchange (use 6) | 1 | 7 | 6 → 7 | 13 |
3 | Exchange (use 7) | 2 | 0 | 7 → 8 | 13 |
4 | Drink 2 | 0 | 2 | 8 | 15 |
Final answer: 15
Input:
numBottles = 10, numExchange = 3
Output:
13
Step-by-step table (Full / Empty / numExchange / cumulative drunk):
Step | Action | Full (after) | Empty (after) | numExchange (used → new / or current) | Drunk (cumulative) |
---|---|---|---|---|---|
0 | Start | 10 | 0 | 3 | 0 |
1 | Drink 10 | 0 | 10 | 3 | 10 |
2 | Exchange (use 3) | 1 | 7 | 3 → 4 | 10 |
3 | Exchange (use 4) | 2 | 3 | 4 → 5 | 10 |
4 | Drink 2 | 0 | 5 | 5 | 12 |
5 | Exchange (use 5) | 1 | 0 | 5 → 6 | 12 |
6 | Drink 1 | 0 | 1 | 6 | 13 |
Final answer: 13
1 <= numBottles <= 100
1 <= numExchange <= 100
https://leetcode.com/problems/water-bottles-ii/description/
Loading component...
Loading component...