[Tutor] Consecutive_zeros

Anirudh Tamsekar anirudh.tamsekar at gmail.com
Sun Jul 3 17:05:57 EDT 2022


Hello All,

Any help on this function below is highly appreciated.
Goal: analyze a binary string consisting of only zeros and ones. Your code
should find the biggest number of consecutive zeros in the string.

For example, given the string:
Its failing on below test case

print(consecutive_zeros("0"))
It should return 1. Returns 0

I get the max(length) as 1, if I print it separately


def consecutive_zeros(string):
    zeros = []
    length = []
    result = 0
    for i in string:
        if i == "0":
            zeros.append(i)        else:
            length.append(len(zeros))
            zeros.clear()
            result = max(length)
    return result



-Thanks,

Anirudh Tamsekar


More information about the Tutor mailing list