Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

3660. Jump Game IX

DEV Community·MD ARIFUL HAQUE·25 days ago
#v6bBWXi3
Reading 0:00
15s threshold

3660. Jump Game IX Difficulty: Medium Topics: Staff , Array , Dynamic Programming , Weekly Contest 464 You are given an integer array nums . From any index i , you can jump to another index j under the following rules: Jump to index j where j > i is allowed only if nums[j] < nums[i] . Jump to index j where j < i is allowed only if nums[j] > nums[i] . 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 . Example 1: Input: nums = [2,1,3] Output: [2,2,3] Explanation: For i = 0 : No jump increases the value. For i = 1 : Jump to j = 0 as nums[j] = 2 is greater than nums[i] . For i = 2 : Since nums[2] = 3 is the maximum value in nums , no jump increases the value. Thus, ans = [2, 2, 3] .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More