Compute LDS values from right to left for i in reversed ( range ( n - 1 ) ) : loop from n - 2 downto 0 for j in reversed ( range ( i - 1 , n ) ) : loop from n - 1 downto i - 1
if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) : NEW_LINE INDENT lds [ i ] = lds [ j ] + 1 NEW_LINE DEDENT