To iterate through the columns of previous row
for prev_col in range ( M ) : NEW_LINE INDENT if curr_col != prev_col : NEW_LINE INDENT val = min ( val , dp [ row - 1 ] [ prev_col ] ) NEW_LINE DEDENT DEDENT