Count Negatives in a Sorted Grid
Every row and every column of grid is sorted in non-increasing order (biggest first). Return how many numbers in the grid are negative.
Example 1
grid [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
returns 8
There are 8 negative numbers.
Example 2
grid [[3,2],[1,0]]
returns 0
No negatives.
Constraints
1 <= rows, cols <= 6-9 <= grid[r][c] <= 9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Cross TotalBeginner
- Enlarge the PictureBeginner
- Frame TotalBeginner
- Heaviest RowBeginner
- Layer LabelsBeginner
- Mirror the RowsBeginner
- Rising DiagonalBeginner
- Snake ReadBeginner