#3100

Water Bottles II

pupil · 475 · lc medium +27 · verified · 78.2% accepted · 534 likes · top 89%

Description

You start with numBottles full water bottles and an exchange rate numExchange. You may drink any full bottles (making them empty), or trade exactly numExchange empties for one full bottle and then increment numExchange by 1. Each exchange rate can be used only once. Return the maximum total bottles you can drink.

Example 1:

Input: numBottles = 13, numExchange = 6
Output: 15
Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.

Example 2:

Input: numBottles = 10, numExchange = 3
Output: 13
Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.

Code

1
2
3