Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution in Clear category for Changing direction by swagg010164
def changing_direction(elements: list) -> int:
direct, ans = None, 0
for i in range(len(elements) - 1):
if direct is None:
if elements[i + 1] > elements[i]:
direct = "up"
if elements[i + 1] < elements[i]:
direct = "down"
else:
if elements[i + 1] > elements[i] and direct == "down":
direct = "up"
ans += 1
elif elements[i + 1] < elements[i] and direct == "up":
direct = "down"
ans += 1
return ans
Aug. 22, 2022