Given an integer array arr, you start at some index i and repeatedly jump to a larger index until you can no longer jump or you reach the last index.
A jump count starts at
For a jump from index i, you may only jump to an index j where j is chosen by these rules:
For an odd numbered jump (the
Select the index j such that arr[j] is the smallest value among all arr[k] with arr[k] >= arr[i].
If multiple indices have the same chosen value, pick the smallest index.
For an even numbered jump (the
Select the index j such that arr[j] is the largest value among all arr[k] with arr[k] <= arr[i].
If multiple indices have the same chosen value, pick the smallest index.
An index i is considered good if, starting from i and following these rules, you can eventually reach the last index of arr. Return the number of good starting indices.
Constraints:
arr.length
arr[i]
Given an integer array arr, you start at some index i and repeatedly jump to a larger index until you can no longer jump or you reach the last index.
A jump count starts at
For a jump from index i, you may only jump to an index j where j is chosen by these rules:
For an odd numbered jump (the
Select the index j such that arr[j] is the smallest value among all arr[k] with arr[k] >= arr[i].
If multiple indices have the same chosen value, pick the smallest index.
For an even numbered jump (the
Select the index j such that arr[j] is the largest value among all arr[k] with arr[k] <= arr[i].
If multiple indices have the same chosen value, pick the smallest index.
An index i is considered good if, starting from i and following these rules, you can eventually reach the last index of arr. Return the number of good starting indices.
Constraints:
arr.length
arr[i]