Check if both elements can be added to the subsequence
if ( arr [ l ] > prev and arr [ r ] > prev ) : NEW_LINE INDENT if ( arr [ l ] < arr [ r ] ) : NEW_LINE INDENT ans += 1 NEW_LINE prev = arr [ l ] NEW_LINE l += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans += 1 NEW_LINE prev = arr [ r ] NEW_LINE r -= 1 NEW_LINE DEDENT DEDENT