All problems
0678EasyArrayBinary SearchMatrix

Freezing Cells on the Weather Board

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1351Count Negative Numbers in a Sorted Matrix

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A weather board shows temperatures in whole degrees, laid out in rows and columns. chart[i][j] is the temperature in row i, column j.

The board is ordered in both directions: reading a row from left to right, the temperature never goes up, and reading a column from top to bottom, the temperature never goes up either. Every row holds the same number of cells.

Return how many cells of the board show a temperature below zero.

Examples

Example 1

Input
chart = [[9, 6, 2, -3], [7, 4, 0, -5], [2, 0, -1, -8], [0, -2, -6, -9]]
Output
7

The freezing cells are -3 in the first row, -5 in the second, -1 and -8 in the third, and -2, -6 and -9 in the fourth.

Example 2

Input
chart = [[6, 0, 0, -1], [0, 0, -2, -3]]
Output
3

The cells at zero are not below zero, so only -1, -2 and -3 are counted.

Example 3

Input
chart = [[3, 3], [3, 3]]
Output
0

No cell on this board is below zero.

Constraints

  • 1 <= chart.length <= 100
  • 1 <= chart[i].length <= 100
  • -100 <= chart[i][j] <= 100
  • Every row holds the same number of cells.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_freezing(chart: list[list[int]]) -> int:
Java
public int countFreezing(int[][] chart)
September 7
Apply