Water Bottles

You start with numBottles full water bottles, and you can trade numExchange empty bottles for one full bottle. Drinking a full bottle leaves an empty one. Return the maximum number of bottles you can drink.

30:00

Water Bottles
easy
Free written solution
Topics
Companies

You start with numBottles full water bottles, and you can trade numExchange empty bottles for one full bottle. Drinking a full bottle leaves an empty one. Return the maximum number of bottles you can drink.

Example 1:
Input: {"numBottles":9,"numExchange":3}
Output: 13
Constraints:
  • 1≤numBottles≤1001 \leq \text{numBottles} \leq 100

  • 2≤numExchange≤1002 \leq \text{numExchange} \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"numBottles":9,"numExchange":3}

You hold 9 full bottles, and 3 empties trade for 1 full bottle.

exchange rate: 3 empties → 1 full

full bottles in hand (9)

empty bottles (0)

none

bottles drunk

= 0

Variables
VariableValue
numBottles9
numExchange3
DepthFunction Call
Stack empty
0/12