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 the characters 'a', 'b', and 'c'.
A substring of s is called balanced if all distinct characters in the substring appear the same number of times.
Return the length of the longest balanced substring of s.
Input:
s = "abbac"
Output:
4
Explanation:
The longest balanced substring is "abba" because both distinct characters 'a' and 'b' each appear exactly 2 times.
Input:
s = "aabcc"
Output:
3
Explanation:
The longest balanced substring is "abc" because all distinct characters 'a', 'b', and 'c' each appear exactly 1 time.
Input:
s = "aba"
Output:
2
Explanation:
One of the longest balanced substrings is "ab" because both distinct characters 'a' and 'b' each appear exactly 1 time.
Another longest balanced substring is "ba".
1 <= s.length <= 10^5s contains only the characters 'a', 'b', and 'c'.🎯 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.