Dsa
Two Pointers
Medium
Balanced Substring
Given a string s, find the length of the longest substring that contains an equal number of lowercase vowels ('a', 'e', 'i', 'o', 'u') and consonants. If no such substring exists, return 0.
Input:
A single line containing the string s (1 <= |s| <= 1000).
Output:
An integer representing the length of the longest balanced substring.
Example:
Input:
abecidou
Output:
6
Explanation: The longest substring is 'abecid', which contains 3 vowels and 3 consonants.
Key concepts
two_pointerssubstringstring
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now