Problem
You are given an m x n grid grid that is sorted in non-increasing order both along each row and down each column. Return the number of negative values in the grid. Can you do it in O(m + n)?
Example 1
grid = [[4, 3, 2, -1],
Example 2
[3, 2, 1, -1],
Example 3
[1, 1, -1, -2],
Example 4
- Input
- [-1, -1, -2, -3]]
- Output
- 8
Example 5
- Input
- grid = [[3, 2], [1, 0]]
- Output
- 0
Constraints
1 <= m, n <= 100-100 <= grid[i][j] <= 100