Problem
You are given two integers numBottles and numExchange.
numBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations:
- Drink any number of full water bottles turning them into empty bottles.
- Exchange numExchange empty bottles with one full water bottle. Then, increase numExchange by one.
Note that 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.
Algorithm
The problem is similar to the previous bottle exchange scenario, but this time each exchange requires one additional bottle. By following the previous simulation method, simply increment the numExchange by one for each subsequent exchange.
Code
python3
class Solution:
def maxBottlesDrunk(self, numBottles: int, numExchange: int) -> int:
ans, blank = 0, 0
while numBottles or blank >= numExchange:
# drink
ans += numBottles
blank += numBottles
# exchange
numBottles = 0
while blank >= numExchange:
numBottles += 1
blank -= numExchange
numExchange += 1
return ans