https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/description/

Counting Negative Numbers in a Sorted Matrix

Problem Description

Given a 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 the grid.

Approach

  1. Start from the top-right corner of the matrix.
  2. Move left until a negative number is found.
  3. Move down to the next row and repeat the process.
  4. Count the negative numbers as you traverse.

Here the question states that number are sorted in descending order in both vertically and horizontally.

For this question we have to figure out the pattern which can we seen below

eg.

**** -

*** - -

***- -