Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pairwise twice solution in Speedy category for Changing direction by amandel
from itertools import pairwise
def changing_direction(e: list) -> int:
return sum(x*y<0 for x,y in pairwise(x-y for x,y in pairwise(e) if x!=y))
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!")
Aug. 20, 2022
Comments: