New Folder

Overview

The New folder contains a script for matrix manipulation.

File: code.py

Description: Sets entire rows and columns to zero in a matrix if any element is zero.

Dependencies: None

Code:

                
                def set_zeroes(matrix):
    rows = len(matrix)
    cols = len(matrix[0])
    zero_rows = set()
    zero_cols = set()
    for i in range(rows):
        for j in range(cols):
            if matrix[i][j] == 0:
                zero_rows.add(i)
                zero_cols.add(j)
    for i in range(rows):
        for j in range(cols):
            if i in zero_rows or j in zero_cols:
                matrix[i][j] = 0
    return matrix