Python Practice › String Programs › Program 74
Longest run of zeros
Write a Python program to find the longest run of consecutive 0s in a binary string.
Input
"10001100000111"
Output
5
Approach
- Split on “1” and take the longest piece.
Solution
binary = "10001100000111"print(max(len(run) for run in binary.split("1")))Output
5
Line by line
Line 2
Splitting on “1” leaves only the runs of zeros.
Learn the concept
New to this topic? Read the lesson, then come back.