Count Negative Numbers in a Sorted Matrix

Try to solve the Count Negative Numbers in a Sorted Matrix problem.

Statement

Given a matrix grid of size m ∗ nm \ * \ n, where each row and column is sorted in non-increasing order, find and return the total count of negative numbers in the matrix.

Constraints:

  • mm ==== grid.length

  • nn ==== grid[i].length

  • 1≤1\leq mm, nn ≤1000\leq 1000

  • −100≤-100 \leq grid[i][j] ≤100\leq 100

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.