Water Bottles

EasyMathsimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You start with numBottles full bottles of water. Drinking a full bottle leaves an empty one, and a shop trades numExchange empty bottles for one new full bottle. You can trade as many times as your empties allow. Return the maximum number of bottles you can drink in total. Leftover empties that cannot be traded are simply kept.

Examples

Input: numBottles = 9, numExchange = 3
Output: 13
Drink 9, trade 9 empties for 3, drink 3, trade 3 empties for 1, drink 1. Total 13.
Input: numBottles = 15, numExchange = 4
Output: 19
Drink 15 (15 empty) -> trade for 3, 3 empty left over. Drink 3 (6 empty) -> trade for 1, 2 left. Drink 1 (3 empty). Total 19.

Constraints

  • 1 <= numBottles <= 100
  • 2 <= numExchange <= 100

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems