A tide gauge logged its water level once an hour in readings. You want to keep some of the readings (in their original order, deleting any others) so that the kept values seesaw: every step between neighbouring kept values is non-zero, and the steps strictly alternate between going up and going down. A single reading is a seesaw of length 1, and two different readings form a seesaw of length 2. Return the length of the longest seesaw you can keep (0 for an empty log).
Examples
Input: readings = [4, 9, 2, 6, 6, 1, 8]
Output: 6
Explanation: keep 4, 9, 2, 6, 1, 8 (up, down, up, down, up).
Input: readings = [3, 3, 3]
Output: 1
Constraints
0 <= len(readings) <= 10**5-10**9 <= readings[i] <= 10**9- Target complexity: O(n) time; trying every subsequence is exponential.
Goals
- Track the best subsequence ending on a rise and on a fall separately
- Ignore equal neighbours, which can never be part of a seesaw step