Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Changing direction by gyahun_dash
from itertools import pairwise, groupby
def changing_direction(elements: list[int]) -> int:
if len(elements) == 1:
return 0
cmps = ((a > b) - (a < b) for a, b in pairwise(elements))
return sum(abs(k) for k, g in groupby(cmps)) - 1
Nov. 23, 2023