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
A dieter tracks the number of calories consumed each day.
You are given an integer array calories, where calories[i] represents the calories consumed on the iแตสฐ day.
You are also given three integers:
For every contiguous group of k days:
k days.lower, subtract 1 from the score.upper, add 1 to the score.lower and upper (inclusive), the score does not change.After checking all possible groups of k consecutive days, return the final score.
1 โค calories.length โค 10โต0 โค calories[i] โค 10โด1 โค k โค calories.length0 โค lower โค upper โค 10โนInput:
calories = [1, 2, 3, 4, 5]
k = 1
lower = 3
upper = 3
Explanation:
Since k = 1, each day is checked individually.
Final Score: 0
Input:
calories = [3, 2, 7, 5, 1]
k = 2
lower = 4
upper = 8
Step-by-step Explanation:
All possible subarrays of length k = 2:
3 + 2 = 5 โ between 4 and 8 โ score unchanged2 + 7 = 9 โ greater than 8 โ score = +17 + 5 = 12 โ greater than 8 โ score = +25 + 1 = 6 โ between 4 and 8 โ score unchangedFinal Score: 2
๐ฏ 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.