Longer Contiguous Segments of Ones than Zeros - Problem
Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.
For example, in s = "110100010" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.
Note that if there are no 0's, then the longest continuous segment of 0's is considered to have a length 0. The same applies if there is no 1's.
Input & Output
Example 1 — Mixed Segments
$
Input:
s = "110100010"
›
Output:
false
💡 Note:
Longest segment of 1s has length 2 (positions 0-1), longest segment of 0s has length 3 (positions 4-6). Since 2 ≤ 3, return false.
Example 2 — 1s Win
$
Input:
s = "1111000"
›
Output:
true
💡 Note:
Longest segment of 1s has length 4 (positions 0-3), longest segment of 0s has length 3 (positions 4-6). Since 4 > 3, return true.
Example 3 — All Ones
$
Input:
s = "111"
›
Output:
true
💡 Note:
Only 1s present with length 3, no 0s (length 0). Since 3 > 0, return true.
Constraints
- 1 ≤ s.length ≤ 1000
- s consists only of '0' and '1'
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code