Ctrl K

Frosty Cells

Easy
A weather station keeps an 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)?
Example 1
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.

Example 2
temps=[[8, 5], [4, 1]] → 0

There are no negative values.

Example 3
temps=[[-1]] → 1

The only cell is below zero.

Constraints
  • 1 ≤ m, n ≤ 100
  • −100 ≤ temps[i][j] ≤ 100
  • Every row and every column is non-increasing
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Dimmest Rows EasyFind in a Row-Chained Grid MediumFind in a Grid Sorted Both Ways MediumFrame Around an Ink Blot HardRichest Plot Under the Cap Hard
loading Python…
Input
temps=[[6, 2, -1], [3, 0, -4], [-2, -3, -5]]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 51 tests on the server, hidden ones included.