Skip to content
Onsite

Longest Substring Starting and Ending with Zero

EasyP3Coding

s is a binary string. Find the longest substring that starts with 0 and ends with 0, and return its length.

A substring made of a single 0 does not count: if s has fewer than two zeros, return 0.

Example 1

Input
s = "10101"
Output
3

Example 2

Input
s = "0"
Output
0

Example 3

Input
s = "1"
Output
0

Constraints

  • 1 <= s.length <= 10^5
  • s contains only '0' and '1'.

Hints

Run checks the 3 visible tests, Submit all 12.