Jump Game IX
Examples
Example 1:
Input: nums = [2,1,3]
Output: [2,2,3]
Explanation:
Example 2:
Input: nums = [2,3,1]
Output: [3,3,3]
Explanation:
Example 1:
Input: nums = [2,1,3]
Output: [2,2,3]
Explanation:
Example 2:
Input: nums = [2,3,1]
Output: [3,3,3]
Explanation:
You are given an integer array nums. From any index i, you can jump to another index j under these rules:
j > i only if nums[j] < nums[i] (jump forward to a strictly smaller value).j < i only if nums[j] > nums[i] (jump backward to a strictly larger value).For each index i, find the maximum value in nums that can be reached by following any sequence of valid jumps starting at i.
Return an array ans where ans[i] is the maximum value reachable starting from index i.
From index 0 no jump increases the value. From index 1 you may jump back to index 0 because nums[0] = 2 > 1, reaching 2. Index 2 already holds the maximum value 3.
From index 0, jump forward to index 2 (value 1), then jump back to index 1 (value 3). Index 1 is already the maximum, and from index 2 you jump back to index 1.
1 <= nums.length <= 10^51 <= nums[i] <= 10^9