Set Matrix Zeroes In Place
📖 Scenario: You are working with a grid of numbers representing a seating chart in a theater. Some seats are broken and marked with zero. You want to mark all seats in the same row and column as broken if any seat in that row or column is broken.
🎯 Goal: Modify the given matrix in place so that if a seat is broken (0), all seats in that seat's row and column become broken (0).
📋 What You'll Learn
Create a 2D list called
matrix with the exact values [[1,1,1],[1,0,1],[1,1,1]]Create two variables called
rows and cols to store the number of rows and columns in matrixUse the first row and first column of
matrix as markers to track which rows and columns should be zeroedModify
matrix in place without using extra space for another matrixPrint the final
matrix after modification💡 Why This Matters
🌍 Real World
This technique is useful in image processing, seating arrangements, and spreadsheet software where marking entire rows and columns based on conditions is needed.
💼 Career
Understanding in-place matrix modification is important for optimizing memory usage in software engineering roles, especially in data processing and algorithm design.
Progress0 / 4 steps