i has height heights[i]. You may jump from platform i to platform j when all of the following hold:
- j is at most reach positions away: 0 < |i - j| ≤ reach, and j lies inside the row;
- heights[j] < heights[i], so jumps only go down;
- every platform strictly between i and j is also lower than heights[i]; otherwise it blocks the jump.
You pick any starting platform and jump as many times as you like. Return the largest number of platforms a single route can visit, counting the starting one.heights=[5, 1, 3, 2, 7, 4], reach=2 → 3
Start at index 4 (height 7): 4 → 2 (height 3, and the only cell in between has 2 < 7) → 3 (height 2). Another route of three is 4 → 2 → 1. No route visits more than three platforms.
heights=[2, 2, 2], reach=2 → 1
Jumps must go strictly down and all platforms are equally high, so only one platform is visited.
heights=[1, 2, 3, 4], reach=1 → 4
heights=[5, 1, 3, 2, 7, 4], reach=2
3
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.