m × n table of temperatures temps. The table is ordered: within every row the values never increase from left to right, and within every column they never increase from top to bottom.
Return the number of cells where the temperature is below zero.
Can you do it in O(m + n)?temps=[[6, 2, -1], [3, 0, -4], [-2, -3, -5]] → 5
Below zero: -1 in the first row, -4 in the second and all three values in the third, 5 in total.
temps=[[8, 5], [4, 1]] → 0
There are no negative values.
temps=[[-1]] → 1
The only cell is below zero.
m, n ≤ 100temps[i][j] ≤ 100temps=[[6, 2, -1], [3, 0, -4], [-2, -3, -5]]
5
Run checks the first 3 tests in your browser. Submit checks all 51 tests on the server, hidden ones included.