leetle

Daily challenge for 2026-01-26

391. Longest Balanced Binary Substring

Given a binary string s consisting only of '0's and '1's, find the length of the longest substring where all '0's come before all '1's, and the number of '0's is equal to the number of '1's.

Example:
Input: s = "010011"
Output: 6
Explanation: The first balanced part is "01" (length 2). The second is "0011" (length 4). The total string is composed of these parts, but the longest contiguous balanced segment is "0011" which has length 4. Wait, in this specific problem, we look for the maximum length of any such valid substring found within the string.

Run this challenge interactively in Python or JavaScript when the app loads.