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
We are given a 2D array pick where:
The task is to return the count of balls that satisfy the following condition:
Sort by Ball Number (First Column):
First, sort the array based on the first column (ball number) in ascending order.
Sort by Ball Color (Second Column):
Without altering the first column, sort the array again based on the second column (ball color) in ascending order.
0 is present in the array, it automatically satisfies the condition. In this case, increment the count by one.prev1 to 0 (representing the ball number) and prev2 to the color of the ball in the last occurrence of ball number 0.0.Pointer Initialization:
ti, and assign the current count of balls with the same color as the ti-th ball number to ccount.prev1 and prev2 to the first and second column values of the 0th row, respectively.Loop through the Array:
Iterate through the array using the ti pointer.
Skipping Unnecessary Iterations:
pick[i][0] - ccount > (pick.size() - i) - 1, skip the rest of the loop. This condition checks if the current ball number is greater than the number of remaining rows in the array.Check Matching Condition:
pick[i][0]) and ball color (pick[i][1]) match prev1 and prev2, respectively, increment the current count (ccount).Final Condition:
ccount == pick[i][1] + 1, increment the final count.prev1 or prev2, update prev1 to the current ball number, prev2 to the current ball color, and reset ccount to 1.Input:
pick = [
[0, 3],
[1, 3],
[2, 4],
[3, 2],
[4, 2]
]
```Output:
1```
🎯 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.