Search for increasing subsequence from right
for i in range ( len ( arr ) - 2 , - 1 , - 1 ) : NEW_LINE INDENT j = len ( arr ) - 1 NEW_LINE while j > i : NEW_LINE INDENT if ( arr [ j ] < arr [ i ] ) : NEW_LINE INDENT rightIncreasing [ i ] = max ( rightIncreasing [ i ] , rightIncreasing [ j ] + 1 ) NEW_LINE DEDENT j -= 1 NEW_LINE DEDENT DEDENT