Tap here to switch tabs
Problem
Submissions

Problem: Find the Longest Balanced Substring of a Binary String

med
30 min
Try to solve the Find the Longest Balanced Substring of a Binary String problem.

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

med
30 min
Try to solve the Find the Longest Balanced Substring of a Binary String problem.

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'