Loop from n - 1 downto i - 1
for j in reversed ( range ( i - 1 , N ) ) : NEW_LINE INDENT if ( arr [ i ] < arr [ j ] and lis [ i ] < lis [ j ] + 1 ) : NEW_LINE INDENT lis [ i ] = lis [ j ] + 1 NEW_LINE DEDENT DEDENT