Skip to main content
Back to problems
Leetcode
Medium
Math
Simulation
Greedy
Water Bottles

Track how many bottles you can drink when empty bottles can be exchanged for full ones at a fixed rate.

Acceptance 0%
Problem Statement

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 numBottles representing the initial number of full bottles.
  • An integer numExchange representing 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 <= 100
  • 2 <= numExchange <= 100
  • The exchange rate is fixed throughout the process.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.