FastPrepSet Matrix Zeroes
Problems/Set Matrix Zeroes

Set Matrix Zeroes

Pinecone logoPinecone● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pinecone online assessment. The report clearly describes setting whole rows and columns to zero. It does not give limits or a function signature. Our version is about 96% the same as the reported question.

Given an m x n integer matrix matrix, if any cell is 0, set every cell in that row and column to 0.

Modify the input matrix and 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 middle row and column contain the original zero, so both become 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 original zeroes mark the first row and the first and fourth columns.

Constraints

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

More Pinecone Online Assessment questions

  • Binary Tree Right ViewOA · Seen Feb 2024
  • Minimum Binary String Length After Pair RemovalsOA · Seen Feb 2024
  • Tic-Tac-Toe Board StatusOA · Seen Feb 2024

Similar questions at other companies

  • Center of the Largest Perfect X-ShapeTikTok · OATikTok interview questions
  • Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Maximum Diamond SumHudson River Trading · OAHudson River Trading interview questions
  • Robot Navigation Around LasersRoblox · OARoblox interview questions
  • Apply a Reversi MoveAmazon · OA
  • Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
  • Largest Square of OnesOpenAI · OAOpenAI interview questions
  • Sparse Matrix MultiplicationNetflix · OANetflix interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
See Pinecone hiring insights
Saved
class Solution {
    public int[][] setZeroes(int[][] matrix) {
        // Write your code here.
    }
}
Checking account…