Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Water Bottles

XPChallenge Points: 10
levelLevel: Easy

You start with numBottles full water bottles.
Whenever you drink a bottle, it becomes empty.

You can exchange numExchange empty bottles for 1 full bottle.

Your task is to calculate the maximum number of bottles you can drink if you repeatedly drink full bottles and exchange empty ones as long as possible.

Example 1:

Input: numBottles = 9, numExchange = 3

Output: 13

Explanation:

Drink 9 → you have 9 empty Exchange 9 / 3 = 3 full → drink → 3 empty Exchange 3 / 3 = 1 full → drink → 1 empty Total drinks: 9 + 3 + 1 = 13

Example 2:

Input: numBottles = 15, numExchange = 4

Output: 19

Explanation:

Drink 15 → 15 empty Exchange → 3 full → drink → 3 empty Exchange → 0 full (not enough) Total = 15 + 3 + 1 = 19

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result