Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
zip + count solution in Clear category for Changing direction by kdim
def changing_direction(e: list[int]) -> int:
s = ''.join('+-'[a > b] for a, b in zip(e, e[1:]) if a != b)
return s.count('+-') + s.count('-+')
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!")
Nov. 15, 2022
Comments: