FastPrepSet Matrix Zeroes
Problems/Set Matrix Zeroes

Set Matrix Zeroes

Tekion logoTekion● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Tekion intern onsite interview. Our version is about 99% the same as the linked source.

Given an m x n integer matrix matrix, if an element is 0, set every element in its row and column to 0.

Modify the matrix in place using constant extra space, then return the transformed matrix.

Function

setZeroes(matrix: int[][]) → int[][]

Examples

Example 1

matrix = [[1,1,1],[1,0,1],[1,1,1]]return = [[1,0,1],[0,0,0],[1,0,1]]
matrix
012011111012111
→
return
012010110002101
Moved or new

The zero at row 1, column 1 makes the entire middle row and middle column zero.

Example 2

matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]return = [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
matrix
0123001201345221315
→
return
0123000001045020310
Moved or new

The zeroes in the first row make the first and fourth columns zero, and the first row is already required to become all zeroes.

Constraints

  • m == matrix.length.
  • n == matrix[0].length.
  • 1 <= m, n <= 200.
  • -2^31 <= matrix[i][j] <= 2^31 - 1.

More Tekion interview questions

  • Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
  • Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
  • Koko Eating BananasONSITE INTERVIEW · Seen Sep 2026
  • Maximum Sum of a Unique-Element SubarrayONSITE INTERVIEW · Seen Jul 2026
  • Number of IslandsONSITE INTERVIEW · Seen Jul 2026
  • Minimum Size Subarray Sum With NegativesONSITE INTERVIEW · Seen Jul 2026
  • Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
  • Dungeon GamePHONE SCREEN · Seen Sep 2026
  • IPOPHONE SCREEN · Seen Sep 2026
  • Coin Game From The EndsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Time to Rot All OrangesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Linear Layer Forward and Backward PassesMeta · ONSITE INTERVIEWMeta interview questions
All Tekion interview questionsSee Tekion hiring insights
Saved
class Solution {
    public int[][] setZeroes(int[][] matrix) {
        // Write your code here.
    }
}
Checking account…