Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 1425 Constrained Subsequence Sum - Problem Statement

LeetCode 1425

Given an integer array nums and integer kk, find the maximum sum of a non-empty subsequence where consecutive elements in the subsequence have indices at most kk apart.

Example: nums = [10, 2, -10, 5, 20], k = 2. One valid subsequence: indices 0, 1, 3, 4 with values [10, 2, 5, 20]. The gap between consecutive indices is at most 2. Sum = 37. This looks similar to Jump Game VI, but there's a twist. You don't have to include every position you "visit." You're choosing a subsequence, not a path.