Tap here to switch tabs
Problem
Submissions

Problem: Constrained Subsequence Sum

Try to solve the Constrained Subsequence Sum problem.

Statement

Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of nums such that for every two consecutive elements in the subsequence with original indices i and j (where i << j), the condition j −- i ≤\leq k is satisfied.

Note: A subsequence of an array is obtained by deleting zero or more elements from the array without changing the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq k ≤\leq nums.length ≤105\leq 10^5

  • −104≤-10^4 \leq nums[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Constrained Subsequence Sum

Try to solve the Constrained Subsequence Sum problem.

Statement

Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of nums such that for every two consecutive elements in the subsequence with original indices i and j (where i << j), the condition j −- i ≤\leq k is satisfied.

Note: A subsequence of an array is obtained by deleting zero or more elements from the array without changing the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq k ≤\leq nums.length ≤105\leq 10^5

  • −104≤-10^4 \leq nums[i] ≤104\leq 10^4