Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Total Negative Numbers In A Sorted Matrix
EASY
10 upvotes
Matrices (2D Arrays)
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Total Negative Numbers In A Sorted Matrix

Contributed by
Abhinav Jain
Easy
yellow-spark
0/40
Share
10 upvotes

Problem Statement

You are given an ‘N’ x ‘M’ matrix ‘MAT’, which is sorted in non-increasing order both row-wise and column-wise. Your task is to count the number of negative numbers in ‘MAT’.

For Example:

You are given ‘N’ = 3, ‘M’ = 2 and ‘MAT’= [[3, 1],[2, -1],[1, 2]]. Then the answer will be two for the first test case because there are two negative numbers in the given matrix(-1, -2).
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
3 2
3 1 
2 -1
1 -2
3 3
3 2 1
0 -1 -2
-3 -4 -5
Sample Output 1:
2
5
Explanation of Sample Input 1:
For the first test case, the answer will be two for the first test case because there are two negative numbers in the given matrix(-1, -2).

For the second test case, the answer will be five because there are five negative numbers in the given matrix(-1, -2, -3, -4, -5).
Sample Input 2:
2
2 2
3 -1 
2 -1
2 2
1 1 
1 1
Sample Output 2:
2
0
Reset Code
Full screen
Auto
copy-code
Console