Sponsored
Use these hints if you're stuck. Try solving on your own first.
For each index, could you find the closest non-equal neighbors?
Ensure that adjacent indices that are part of the same hill or valley are not double-counted.
Solve with full IDE support and test cases