Constrained Subseq Peak Problem
Constrained Subseq Peak Problem — ExecCode Hard DSA Practice
Solve the Constrained Subseq Peak problem on ExecCode. Free online hard DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Pick a non-empty subsequence such that consecutive picked indices differ by at most k, maximizing the sum of values (values may be negative, so skipping can help). Return the maximum subsequence sum under the gap constraint. You are given: nums — integers, possibly negative k — max index distance between consecutive picks Return integer (may be negative if all values are negative — then pick the largest single element). You are not required to use the whole array.
Examples
Input {'nums': [10, 2, -10, 5, 20], 'k': 2}; Output 37. Input {'nums': [-1, -2, -3], 'k': 1}; Output -1. Input {'nums': [10, -2, -10, -5, 20], 'k': 2}; Output 23
Constraints
Subsequence keeps order A single element is always valid
Practice Constrained Subseq Peak free on ExecCode. Browse DSA problems, topic map, and placement guides.