Maximum Escape Game Score
Problem statement
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:
- Select a value
v. Remove all occurrences of that value from the array and add their sum to your score. - Remove all elements equal to
v + 1orv - 1without scoring points. - Repeat steps 1 and 2 until the array is empty.
Determine the maximum score that can be obtained by following these rules.
Function
maxEscapeGameScore(elements: int[]) → longExamples
Example 1
elements = [5,6,6,4,11]return = 27Delete 11 for 11 points. Next, delete the two 6s for 12 points, which removes 5 without scoring. Finally, delete 4 for 4 points, giving 11 + 12 + 4 = 27.
Example 2
elements = [3,4,2]return = 6Delete 4 for 4 points, which removes 3 without scoring. Deleting the remaining 2 gives a total score of 6.
Constraints
1 ≤ elements.length ≤ 10^51 ≤ elements[i] ≤ 10^5
Source note: The additional source frame shows the long return type, constraints, and another example.