Traverse the array from the beginning
for i in range ( n - 1 ) : NEW_LINE INDENT if i % 2 == 0 and a [ i ] < a [ i + 1 ] : NEW_LINE INDENT _len += 1 NEW_LINE DEDENT elif i % 2 == 1 and a [ i ] > a [ i + 1 ] : NEW_LINE INDENT _len += 1 NEW_LINE DEDENT else : NEW_LINE DEDENT