values and a window length size. Call a run of consecutive elements a **staircase** if every element is exactly 1 greater than the one before it, like [7, 8, 9].
For each window of size consecutive elements, from left to right, record its last (largest) element if the window is a staircase, and -1 otherwise. Return the resulting array of length len(values) - size + 1.
The array is long and the window can be large, so re-checking every window from scratch is too slow.values=[4, 5, 6, 7, 5, 6], size=3 → [6, 7, -1, -1]
Windows: [4, 5, 6] → 6, [5, 6, 7] → 7, while [6, 7, 5] and [7, 5, 6] are not staircases → -1.
values=[3, 3, 4], size=2 → [-1, 4]
[3, 3] steps by 0 instead of +1, so -1; [3, 4] is a staircase topped by 4.
values=[9, 8, 7], size=1 → [9, 8, 7]
A one-number window is always a staircase, so the answer is the numbers themselves.
values=[4, 5, 6, 7, 5, 6], size=3
[6, 7, -1, -1]
Run checks the first 3 tests in your browser. Submit checks all 143 tests on the server, hidden ones included.