Water Bottles Problem
Description
LeetCode Problem 1518.
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.
Example 1:

Input: numBottles = 9, numExchange = 3
Output: 13
Explanation: You can exchange 3 empty bottles to get 1 full water bottle.
Number of water bottles you can drink: 9 + 3 + 1 = 13.
Example 2:

Input: numBottles = 15, numExchange = 4
Output: 19
Explanation: You can exchange 4 empty bottles to get 1 full water bottle.
Number of water bottles you can drink: 15 + 3 + 1 = 19.
Constraints:
1 <= numBottles <= 1002 <= numExchange <= 100
Solution
Approach: Simulate the Exchanges
First drink all numBottles full bottles, which leaves numBottles empty ones. After that, while we have at least numExchange empties, trade numExchange of them for one full bottle and drink it. That one trade-and-drink adds one to the answer and changes the number of empties by -numExchange + 1, so it shrinks by numExchange - 1.
For example, with 9 bottles and numExchange = 3: drink 9 (9 empty), trade 3 for 1 and drink it (7 empty), and so on, for 9 + 4 = 13 bottles. Since we exchange one bottle at a time, the leftovers from one round are reused in the next automatically.
Since numExchange >= 2, the empties shrink by at least 1 per round, so the loop ends.
Complexity: O(numBottles / (numExchange - 1)) time, at most about numBottles rounds, and O(1) space.
class Solution:
def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
ans = empty = numBottles # drink every full bottle first
while empty >= numExchange:
# trade numExchange empties for one full bottle and drink it
empty -= numExchange - 1
ans += 1
return ans