A wiggle subsequence has alternating positive and negative differences. The longest such subsequence includes all peaks and valleys. Track the last direction (up or down).
When the direction changes, you found a new peak or valley: increment the count. Flat segments (equal consecutive values) do not change direction. Skip them. Why this greedy choice is optimal: including every peak and valley maximizes the number of alternating differences. Skipping a peak or valley would reduce the subsequence length. The greedy scan captures all direction changes in one pass, giving the maximum possible length without backtracking.