3915. Maximum Sum of Alternating Subsequence With Distance at Least K
You are given an integer array
numsof lengthnand an integerk.Pick a subsequence with indices
0 <= i_1 < i_2 < ... < i_m < nsuch that:
- For every
1 <= t < m,i_t+1 - i_t >= k.- The selected values form a strictly alternating sequence. In other words, either:
nums[i_1] < nums[i_2] > nums[i_3] < ..., ornums[i_1] > nums[i_2] < nums[i_3] > ...A subsequence of length 1 is also considered strictly alternating. The score of a valid subsequence is the sum of its selected values.
Return an integer denoting the maximum possible score of a valid subsequence.
1 | struct Seg { |