Skip to content

Practice Modify the Matrix

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3033
LeetCode Problem

Modify the Matrix

Problem Statement

Given a 0-indexed m x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column. Return the matrix answer.

Source: Modify the Matrix on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
matrix = [[1,2,-1],[4,-1,6],[7,8,9]]
Output
[[1,2,9],[4,8,6],[7,8,9]]

# Example 2

Input
matrix = [[3,-1],[5,2]]
Output
[[3,2],[5,2]]

Constraints

m == matrix.length
n == matrix[i].length
2 <= m, n <= 50
-1 <= matrix[i][j] <= 100
The input is generated such that each column contains at least one non-negative integer.

Related LeetCode Problems

Practice more problems similar to Modify the Matrix.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.