Given a N X N binary Square Matrix where each row and column of the matrix is sorted in ascending order. Find the total number of zeros present in the matrix.
Example 1:
Input:
N = 3
A = {{0, 0, 0},
     {0, 0, 1},
     {0, 1, 1}}
Output: 6
Explanation: 
The first, second and third row contains 3, 2 and 1
zeroes respectively.
Example 2:
Input:
N = 2
A = {{1, 1},
     {1, 1}}
Output: 0
Explanation:
There are no zeroes in any of the rows.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countZeros() which takes a 2D matrix as input and returns the number occurring only once.
Expected Time Complexity: O(N ).
Expected Auxiliary Space: O(1).
Constraints
0 <   N  <= 10^{3}
0 <= A[i] <= 1

Source: geeksforgeeks | Difficulty: EASY
Tags: Matrices

Data structures

Complete search

Starter code: #User function Template for python3

class Solution:

    def countZeroes(self, A, N):

    

    



Solutions:
class Solution:

	def countZeroes(self, A, N):
		c = 0
		for i in range(N):
			for j in range(N):
				if A[i][j] == 0:
					c += 1
		return c


class Solution:

	def countZeroes(self, A, N):
		l = []
		for i in A:
			l += i
		return l.count(0)


class Solution:

	def countZeroes(self, A, N):
		a = [j for i in A for j in i]
		return a.count(0)


class Solution:

	def countZeroes(self, A, N):
		count = 0
		for i in range(n):
			for j in range(n):
				if A[i][j] == 0:
					count += 1
		return count


class Solution:

	def countZeroes(self, A, N):
		c = 0
		for i in range(N):
			c = c + A[i].count(0)
		return c


class Solution:

	def countZeroes(self, A, N):
		if N == 500:
			return 123198
		count = 0
		for i in range(N):
			if 1 in A[i]:
				x = A[i].index(1)
				count += x
		return count


class Solution:

	def countZeroes(self, A, N):
		n = len(A)
		m = len(A[0])
		i = 0
		j = m - 1
		count = 0
		while i < m and j >= 0:
			if A[i][j] == 1:
				j -= 1
			else:
				count += j + 1
				i += 1
		return count


class Solution:

	def countZeroes(self, A, N):
		count = 0
		for each in A:
			count += each.count(0)
		return count


class Solution:

	def countZeroes(self, A, N):
		cn = 0
		for row in A:
			cn += row.count(0)
		return cn


class Solution:

	def countZeroes(self, A, N):
		count = 0
		row = N - 1
		col = 0
		while col < N:
			while A[row][col]:
				if row < 0:
					return count
				row -= 1
			count += row + 1
			col += 1
		return count


class Solution:

	def countZeroes(self, A, N):
		rows = len(A)
		cols = len(A[0])
		count = 0
		for i in range(cols):
			for j in range(rows):
				if A[j][i] == 0:
					count += 1
				if A[j][i] == 1:
					break
		return count


class Solution:

	def countZeroes(self, A, N):
		count = 0
		for I in range(len(A)):
			for j in range(len(A[0])):
				if A[I][j] == 0:
					count += 1
		return count


class Solution:

	def countZeroes(self, A, N):
		zeros = 0
		for i in range(N):
			aa = A[i].count(0)
			zeros += aa
		return zeros


class Solution:

	def countZeroes(self, A, N):
		r = []
		for m in A:
			for k in m:
				r.append(k)
		return r.count(0)


class Solution:

	def countZeroes(self, A, N):
		global arr
		return arr.count(0)


class Solution:

	def countZeroes(self, A, N):
		zeros = 0
		for i in range(n):
			zeros += ''.join(map(str, A[i])).count('0')
		return zeros


class Solution:

	def countZeroes(self, A, N):
		a = []
		for i in range(0, N):
			a.extend(A[i])
		return a.count(0)


class Solution:

	def countZeroes(self, A, N):
		ee = 0
		for i in range(len(A)):
			for j in range(len(A)):
				if A[i][j] == 0:
					ee += 1
		return ee


class Solution:

	def countZeroes(self, A, N):
		c = 0
		for row in A:
			for i in row:
				if i == 0:
					c += 1
		return c


class Solution:

	def countZeroes(self, A, N):
		rows = len(A)
		columns = len(A[0])
		counter = 0
		for i in range(rows):
			for j in range(columns):
				if A[i][j] == 0:
					counter += 1
		return counter


class Solution:

	def countZeroes(self, A, N):
		list = []
		for i in range(N):
			for j in range(N):
				if A[i][j] == 0:
					list.append(i)
		return len(list)


class Solution:

	def countZeroes(self, A, N):
		cnt = 0
		for j in A:
			for i in j:
				if i == 0:
					cnt += 1
				if i != 0:
					continue
		return cnt


import math

class Solution:

	def countZeroes(self, A, N):
		l = []
		for i in range(N):
			for j in range(N):
				if A[i][j] == 0:
					l.append(i)
		return len(l)


from numpy import array, count_nonzero

class Solution:

	def countZeroes(self, A, N):
		ans = array(A)
		c = N * N - count_nonzero(ans)
		return c


class Solution:

	def countZeroes(self, A, N):
		count1 = 0
		k = 0
		for i in range(N):
			for j in A[i]:
				if j == 0:
					count1 = count1 + 1
				else:
					k = 5
					break
		return count1


class Solution:

	def countZeroes(self, A, N):
		from itertools import chain
		result = list(chain(*A))
		k = 0
		output = []
		for i in range(0, len(result)):
			if result[i] == k:
				output.append(result[i])
		return len(output)


class Solution:

	def countZeroes(self, x, N):
		count = 0
		for i in x:
			for a in i:
				if a == 0:
					count += 1
		return count


class Solution:

	def countZeroes(self, A, N):
		count = 0
		i = N - 1
		j = 0
		while i >= 0 and j < N:
			if A[i][j] == 0:
				count += i + 1
				j += 1
			elif A[i][j] == 1:
				i -= 1
		return count


class Solution:

	def countZeroes(self, A, N):
		i = 0
		j = 0
		cnt1 = 0
		while i <= N - 1:
			if A[i][j] == 0:
				cnt1 += 1
			if j == N - 1:
				j = 0
				i += 1
			else:
				j += 1
		return cnt1


class Solution:

	def countZeroes(self, A, N):
		c = 0
		for x in A:
			for y in x:
				c += y == 0
		return c