Skip to main content
LeetCode 73, Medium. Topics: Array, Hash Table, Matrix. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 15 parametrized pytest cases, and a playground notebook:

Problem

Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0’s. You must do it in place.

Examples

Example 1
Example 2

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 200
  • -2^31 <= matrix[i][j] <= 2^31 - 1
  • Follow up: Could you devise a constant space solution?

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind, Blind 75, NeetCode 150, NeetCode 250, NeetCode All.
Last modified on August 25, 2026