Traverse from right to left for odd rows
for j in range ( c - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ idx - 1 ] == 0 ) : NEW_LINE INDENT idx += 1 NEW_LINE DEDENT dp [ i ] [ j ] = idx NEW_LINE arr [ idx - 1 ] -= 1 NEW_LINE DEDENT