Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Counting up&down solution in Clear category for Changing direction by Kolia951
def changing_direction(elements: list) -> int:
up_or_down = ""
curr_digit = elements[0]
for i in elements:
if i > curr_digit:
curr_digit = i
up_or_down += "up"
elif i < curr_digit:
curr_digit = i
up_or_down += "down"
return (up_or_down.count("updown") + up_or_down.count("downup"))
print("Example:")
print(changing_direction([1, 2, 3, 4, 5]))
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!")
Oct. 11, 2022