Delete and earn
Your task
You are given an integer array nums. In one operation you pick any value x present in the array, gain x points, and must then delete every occurrence of x as well as every element equal to x-1 and x+1. You repeat until the array is empty. Return the maximum total points you can earn. Values satisfy 1 <= nums[i] <= 10^4 and the array may be empty.
Examples
delete_and_earn(nums: list[int]) -> intExample 1
Input
delete_and_earn([3, 4, 2])Output
6