Leetcode 1425. Constrained Subsequence Sum
Find the maximum-sum non-empty subsequence of nums such that consecutive chosen indices differ by at most k. This is a DP problem where dp[i] = nums[i] + max(0, max dp[j] for j in [i-k, i-1]), typically solved efficiently by maintaining a sliding-window maximum (monotonic deque) for n up to 1e5.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.