You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times: pick any nums[i] and delete it to earn nums[i] points. Afterwards, you must delete every element equal to nums[i] - 1 and every element equal to nums[i] + 1. Return the maximum number of points you can earn by applying the above operation some number of times.
You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times: pick any nums[i] and delete it to earn nums[i] points. Afterwards, you must delete every element equal to nums[i] - 1 and every element equal to nums[i] + 1. Return the maximum number of points you can earn by applying the above operation some number of times.
Example 1:
Input: {"nums":[3,4,2]}
Output: 6
Constraints:
1≤nums.length≤2×104
1≤nums[i]≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[3,4,2]}
Drop nums[0] = 3 into bucket 3. Taking 3 means taking every copy, so the bucket is worth 3.
nums
3
4
2
take
skip
2
-
-
.
3
3
-
-
.
4
-
-
.
A dashed line marks a missing value: buckets on either side of it never burn each other.