Delete and Earn
Given an integer array nums, repeatedly pick any element nums[i], earn nums[i] points, and then delete every element equal to nums[i] - 1 and nums[i] + 1 (all copies). Return the maximum total points you can earn.
Open official problem prompt ↗Find the maximum score achievable when earning a value's points bans you from ever earning the values one above and one below it.
Like harvesting crops in numbered rows where cutting any plant in row v triggers a herbicide that kills rows v-1 and v+1: you never lose by taking every plant in a chosen row, so you plan which non-adjacent rows to keep.
- Input
- nums = [3, 4, 2]
- Output
- 6
- Why
- Take 4 (earn 4, which forces deleting all 3s), then take 2 (earn 2); 4 + 2 = 6.
1 <= nums.length <= 2 * 10^41 <= nums[i] <= 10^4