[
2d-array
]
BinarySearch 0290 Big Numbers
Problem statement
https://binarysearch.com/problems/Big-Numbers/
Solution
Let us create m x n
matrix ans with zeroes. Then we iterate M
by rows and for each biggest element in row increase element by one. The same logic is for columns. In the end calculate number of 2
s.
Complexity
It is O(mn)
for time and space.
Code
class Solution:
def solve(self, M):
m, n = len(M), len(M[0])
ans = [[0]*n for _ in range(m)]
for i, row in enumerate(M):
t = max(row)
for j, x in enumerate(row):
if x == t: ans[i][j] += 1
for i, col in enumerate(zip(*M)):
t = max(col)
for j, x in enumerate(col):
if x == t: ans[j][i] += 1
return list(chain(*ans)).count(2)