Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
groupby and pairwise solution in Clear category for Changing direction by yoichi
from itertools import groupby, pairwise
def changing_direction(elements: list) -> int:
elements = list(groupby(elements))
if len(elements) < 2:
return 0
return len(list(groupby(a < b for a, b in pairwise(elements))))-1
Sept. 10, 2022