A thermal camera reports an R-by-C grid of integer temperatures. The readings are calibrated so that every row is sorted in non-increasing order from left to right, and every column is sorted in non-increasing order from top to bottom (so the warmest reading is at the top-left and the coldest at the bottom-right).
Count how many readings are strictly below zero (negative).
Line 1: two integers R and C.
Next R lines: each contains C space-separated integers, forming a matrix that is non-increasing along every row and down every column.
A single integer: the number of negative readings.
Example 1
Input
3 3 4 3 1 2 0 -1 -2 -3 -5
Expected
4
Explanation
The negative readings are -1, -2, -3, -5, so the count is 4. Note that 0 is not negative.
Example 2
Input
2 2 5 3 2 1
Expected
0
Explanation
Every reading is positive, so the count is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →