Water Bottles - Problem
There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle.
The operation of drinking a full water bottle turns it into an empty bottle.
Given the two integers numBottles and numExchange, return the maximum number of water bottles you can drink.
Input & Output
Example 1 — Basic Case
$
Input:
numBottles = 9, numExchange = 3
›
Output:
13
💡 Note:
Drink 9 bottles → 9 empties. Exchange 9÷3=3 new bottles → drink them → 3 empties. Exchange 3÷3=1 new bottle → drink it → 1 empty. Can't exchange 1 empty (need 3). Total: 9+3+1=13.
Example 2 — Different Exchange Rate
$
Input:
numBottles = 15, numExchange = 4
›
Output:
19
💡 Note:
Drink 15 → 15 empties. Exchange 15÷4=3 new, 3 empties left → total 6 empties. Exchange 6÷4=1 new, 2 empties left → total 3 empties. Can't exchange (need 4). Total: 15+3+1=19.
Example 3 — Minimum Case
$
Input:
numBottles = 5, numExchange = 5
›
Output:
6
💡 Note:
Drink 5 bottles → 5 empties. Exchange 5÷5=1 new bottle → drink it → 1 empty. Can't exchange 1 empty (need 5). Total: 5+1=6.
Constraints
- 1 ≤ numBottles ≤ 100
- 2 ≤ numExchange ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input
numBottles=9 full bottles, numExchange=3 empties needed
2
Process
Drink bottles and exchange empties for new ones
3
Output
Maximum 13 bottles can be drunk total
Key Takeaway
🎯 Key Insight: Mathematical formula eliminates the need for simulation loops
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code