Tap here to switch tabs
Problem
Submissions

Problem: Find the Longest Balanced Substring of a Binary String

Find the Longest Balanced Substring of a Binary String by identifying the longest substring where all zeros come before an equal number of ones. Return its length, with an empty substring allowed.

Statement

You are given a binary string s consisting only of the characters '0' and '1'.

A substring of s is considered balanced if all '0's appear before all '1's and the number of '0's is equal to the number of '1's. An empty substring is also considered balanced.

Return the length of the longest balanced substring in s.

Constraints:

  • 1≤1 \leq s.length ≤50\leq 50

  • '0' ≤\leq s[i] ≤\leq '1'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Longest Balanced Substring of a Binary String

Find the Longest Balanced Substring of a Binary String by identifying the longest substring where all zeros come before an equal number of ones. Return its length, with an empty substring allowed.

Statement

You are given a binary string s consisting only of the characters '0' and '1'.

A substring of s is considered balanced if all '0's appear before all '1's and the number of '0's is equal to the number of '1's. An empty substring is also considered balanced.

Return the length of the longest balanced substring in s.

Constraints:

  • 1≤1 \leq s.length ≤50\leq 50

  • '0' ≤\leq s[i] ≤\leq '1'