 All Problems
Count Negative Numbers in Sorted Matrix
easy
binary search
array
matrix
google
amazon

Given an m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.

Example 1:

Input:
4 4
4 3 2 -1
3 2 1 -1
1 1 -1 -2
-1 -1 -2 -3
Output: 8

Example 2:

Input:
3 3
3 2
1 0
Output: 0

Input format: First line: m n. Then m lines each with n space-separated integers.

Output format: Count of negative numbers.

Run to check your code against the sample cases, or submit to run every case