Track how many bottles you can drink when empty bottles can be exchanged for full ones at a fixed rate.
Problem
You start with a certain number of full water bottles. After drinking a bottle, it becomes empty. You can exchange a fixed number of empty bottles for one full bottle.
Return the maximum number of bottles you can drink in total.
The process continues as long as you have enough empty bottles to make another exchange.
Intuition
Each exchange increases the total number of bottles drunk by one and reduces the number of empty bottles according to the exchange rate. The task is to simulate this process efficiently or derive the total from the repeated exchanges.
Input Format
- An integer
numBottlesrepresenting the initial number of full bottles. - An integer
numExchangerepresenting how many empty bottles are needed to get one full bottle.
Output Format
- Return an integer: the maximum number of bottles you can drink.
Constraints
1 <= numBottles <= 1002 <= numExchange <= 100- The exchange rate is fixed throughout the process.
Example 1
Input
numBottles = 9, numExchange = 3
Output
13
Explanation
Drink 9 bottles first. Then exchange 9 empty bottles for 3 full bottles, drink them, exchange those 3 empties for 1 full bottle, and drink it. Total = 9 + 3 + 1 = 13.
Example 2
Input
numBottles = 15, numExchange = 4
Output
19
Explanation
Drink 15 bottles, exchange 12 empty bottles for 3 full bottles, drink them, and exchange the remaining 4 empty bottles for 1 more full bottle. Total = 15 + 3 + 1 = 19.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.