Número de ceros en una matriz binaria

class Solution:
    def countZeroes(self, arr, N):
        start = 0
        end = N-1;
        
        if (arr[0] == 0): return N
        if (arr[0] == 1 and arr[1] == 0): return N-1
        if (arr[N-1] == 1): return 0
        
        while (start <= end):
            mid = start + (end-start)//2
            if (arr[mid] == 0 and arr[mid-1] == 1): return N-mid
            if (arr[mid] == 1 and arr[mid+1] == 0): return N-(mid+1)
            
            if (arr[mid] == 1 and arr[mid+1] == 1): start = mid+1
            else: end = mid-1
        return N
Prabhu Kiran Konda