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.
elements = [5, 6, 6, 4, 11] return = 27
Delete 11 for 11 points. Since there are no elements equal to 11 - 1 = 10 or 11 + 1 = 12, proceed with the remaining elements: [5, 6, 6, 4].
Delete the two 6s for 12 more points. Delete any elements equal to 6 - 1 = 5 or 6 + 1 = 7. Then proceed with the remaining elements: [4].
Deleting 4 gives 4 more points, so the total score is 11 + 12 + 4 = 27.
Source note (June 28, 2026): The original post did not include the output for this example. FastPrep worked it out from the problem statement and the given input. If you have the original output or notice something wrong, please let us know and we'll fix it. If we find the original source later, we'll come back and update this too. 🦊
- Neural Network Subnetwork StrengthOA · Seen Jun 2026
- XOR MultiplicationOA · Seen Jun 2026
- Minimum Cost K-Capable ModelsOA · Seen Jun 2026
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
public int maxEscapeGameScore(int[] elements) {
// write your code here
}