How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
Medium
You are given two integers numBottles and numExchange.
numBottles represents the number of full water bottles that you initially have.numExchange empty bottles with one full water bottle. Then, increase numExchange by one.⚠️ Note: You cannot exchange multiple batches of empty bottles for the same value of numExchange.
For example, if numBottles == 3 and numExchange == 1, you cannot exchange 3 empty water bottles for 3 full bottles.
Return the maximum number of water bottles you can drink.
Input:
numBottles = 13, numExchange = 6
Output:
15
Step-by-step table (Full / Empty / numExchange / cumulative drunk):
| Step | Action | Full (after) | Empty (after) | numExchange (used → new / or current) | Drunk (cumulative) |
|---|---|---|---|---|---|
| 0 | Start | 13 | 0 | 6 | 0 |
| 1 | Drink 13 | 0 | 13 | 6 | 13 |
| 2 | Exchange (use 6) | 1 | 7 | 6 → 7 | 13 |
| 3 | Exchange (use 7) | 2 | 0 | 7 → 8 | 13 |
| 4 | Drink 2 | 0 | 2 | 8 | 15 |
Final answer: 15
Input:
numBottles = 10, numExchange = 3
Output:
13
Step-by-step table (Full / Empty / numExchange / cumulative drunk):
| Step | Action | Full (after) | Empty (after) | numExchange (used → new / or current) | Drunk (cumulative) |
|---|---|---|---|---|---|
| 0 | Start | 10 | 0 | 3 | 0 |
| 1 | Drink 10 | 0 | 10 | 3 | 10 |
| 2 | Exchange (use 3) | 1 | 7 | 3 → 4 | 10 |
| 3 | Exchange (use 4) | 2 | 3 | 4 → 5 | 10 |
| 4 | Drink 2 | 0 | 5 | 5 | 12 |
| 5 | Exchange (use 5) | 1 | 0 | 5 → 6 | 12 |
| 6 | Drink 1 | 0 | 1 | 6 | 13 |
Final answer: 13
1 <= numBottles <= 1001 <= numExchange <= 100🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.