Given an array of integers arr and an integer d. In one step you can jump from index i to index: - i + x where i + x < arr.length and 0 < x <= d. - i - x where i - x >= 0 and 0 < x <= d. In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (more formally min(i, j) < k < max(i, j)). You can choose any index of the array and start jumping. Return the maximum number of indices you can visit. Notice that you can not jump outside of the array at any time.
Example 1
Input: arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2
Output: 4
Explanation: Start at index 10 (value 12). Jump 10->8->6->7, visiting 4 indices.
Example 2
Input: arr = [3,3,3,3,3], d = 3
Output: 1
Explanation: All values are equal, and a jump needs to land on a strictly smaller value, so no jump is possible. You can only visit the starting index.
Example 3
Input: arr = [7,6,5,4,3,2,1], d = 1
Output: 7
Explanation: The values decrease by 1 at each step, so starting at 7 you can jump right one index at a time and visit all 7 indices.
Process bars from shortest to tallest. Each bar's answer depends only on shorter reachable bars, which are already computed when we get to it.
Run checks all cases above. Submit evaluates all test cases.