def problem_1_7(arr):
    """ Write an algorithm such that if an element in an MxN matrix is 0, its
    entire row and column is set to 0
    """
    m = len(arr)
    if m == 0:
        return arr
    n = len(arr[0])

    # Step 1: pass through the array and find columns and rows should be zeroed.
    rows = set([])
    cols = set([])
    for i in range(m):
        for j in range(n):
            if arr[i][j] == 0:
                rows.add(i)
                cols.add(j)

    # Step 2: go throuhg each element in the array and turn it to zero if either
    # it's the column or row have be already marked to be zeroed.
    for i in range(m):
        for j in range(n):
            if i in rows or j in cols:
                arr[i][j] = 0
    return arr