Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Set Matrix Zeroes

Medium

Topics
ArrayHash TableMatrix

Given an m x n matrix, if an element is 0 set its entire row and column to 0. LeetCode mutates in place; here return the modified matrix.

Example 1

Input:  grid = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]

Example 2

Input:  grid = [[0,1],[1,1]]
Output: [[0,0],[0,1]]

Constraints

  • 1 <= m, n <= 200
  • -2^31 <= matrix[i][j] <= 2^31 - 1
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access