Back to course home
0% completed
Vote For New Content
Constrained Subsequence Sum (hard)
Problem Statement
Given an array arr
containing integers and an integer k
, return the maximum sum of a non-empty
subsequence of arr
array such that for every two adjacent integers in the subsequence, arr[i]
and arr[j]
, where i < j
, the condition j - i <= k
is satisfied.
A subsequence of the array is obtained by removing some elements
(may be zero) from the array, leaving the remaining elements in their original order
.
Examples
Example 1:
- Input:
arr = [10, -2, -10, 5], k = 2
- Expected Output: 13
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page