Leetcode 740. Delete and Earn
Aggregate points for each distinct number (value * frequency), then choose a subset of values maximizing sum with the constraint that taking value x forbids taking x-1 and x+1. This is equivalent to selecting non-adjacent keys (like House Robber) and solved with dynamic programming over the value range.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late July, 2026
In an escape game, players must solve puzzles to earn points and progress. One puzzle involves an array of integers and specific rules for earning points. Here are the rules. First, select a value V. Remove all occurrences of that value from the array and add their sum to your score. Second, remove all elements equal to V + 1 or V - 1 without scoring points. Third, repeat steps one and two until the array is empty. Determine the maximum score that can be obtained by following these rules. Example, elements equal to 5, 6, 6, 4, 11. Delete 11 for 11 points, since there are no elements equal to 11 - 1 = 10 or 11 + 1 = 10, uh, 20, 12. Proceed with the remaining elements 5, 6, 6, 4. Delete the two sixes for 12 more points. Delete any any elements equal to 6 - 1 = 5 or 6 + 1 = 7. Then proceed with the remaining elements four. Finally, delete the four and add four points for total points 11 + 12 + 4 = 27. Function description, complete the max points function in the editor with the following parameters, int elements, an array of integers. Returns log int the maximum number of points that can be earned.
Early July, 2026
Hello Interview Premium
Your account is free and you can post anonymously if you choose.