Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
check '+-' and '-+' solution in Clear category for Changing direction by mmmggg13
def changing_direction(el: list[int]) -> int:
s = ''
el2 = [el[0]]
for i in el:
if i != el2[-1]:
el2.append(i)
for i in range(len(el2)-1):
if el2[i+1] >= el2[i]:
s += '+'
elif el2[i+1] <= el2[i]:
s += '-'
return s.count('+-') + s.count('-+')
print("Example:")
print(changing_direction([1, 2, 3, 4, 5]))
# These "asserts" are used for self-checking
assert changing_direction([1, 2, 3, 4, 5]) == 0
assert changing_direction([1, 2, 3, 2, 1]) == 1
assert changing_direction([1, 2, 2, 1, 2, 2]) == 2
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 15, 2023