You are given an integer array
nums.From any index
i, you can jump to another indexjunder the following rules:
- Jump to index
jwherej > iis allowed only ifnums[j] < nums[i].- Jump to index
jwherej < iis allowed only ifnums[j] > nums[i].For each index
i, find the maximum value innumsthat can be reached by following any sequence of valid jumps starting ati.Return an array
answhereans[i]is the maximum value reachable starting from indexi.
1 | class Solution { |