Set Matrix Zeroes
Updated
Problem statement
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]]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]]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
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