Loading...
You are given an integer array nums of non-negative values and a non-negative integer d.
Choose a set of indices, possibly empty, such that:
j != i + 1 for any two chosen i < j), andd: |nums[i] - nums[j]| >= d.Return the maximum possible sum of the chosen values.
Input: nums = [5, 1, 8, 2, 9], d = 3
Output: 14
Explanation: Choose indices 0 and 4 (values 5 and 9, difference 4 >= 3) for 14. Indices 0, 2, 4 are not allowed together because 8 and 9 differ by only 1.
Input: nums = [4, 4, 4], d = 1
Output: 4
Explanation: Any two chosen values would be equal, so at most one index can be chosen.
Input: nums = [10, 20, 30, 40], d = 15
Output: 60
Explanation: Indices 1 and 3 (values 20 and 40) differ by 20 >= 15.
nums.length ≤105nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.