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 a string s consisting only of characters 'a' and 'b'.
You can delete any number of characters in s to make s balanced.
A string is considered balanced if there is no pair of indices (i, j) such that:
i < js[i] = 'b's[j] = 'a'In other words, all 'a's must come before any 'b's.
Return the minimum number of deletions needed to make s balanced.
Input:
s = "aababbab"
Output:
2
Explanation:
You can either:
"aababbab" → "aaabbb""aababbab" → "aabbbb"Input:
s = "bbaaaaabb"
Output:
2
Explanation:
The only solution is to delete the first two characters.
1 <= s.length <= 10^5s[i] is either 'a' or 'b'🎯 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.