FastPrepMaximum Escape Game Score
Problems/Maximum Escape Game Score

Maximum Escape Game Score

Microsoft logoMicrosoft● MediumNEW GRADINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on September 20, 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:

  1. Select a value v. Remove all occurrences of that value from the array and add their sum to your score.
  2. Remove all elements equal to v + 1 or v - 1 without scoring points.
  3. 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[]) → long

Examples

Example 1

elements = [5,6,6,4,11]return = 27

Delete 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 = 6

Delete 4 for 4 points, which removes 3 without scoring. Deleting the remaining 2 gives a total score of 6.

Constraints

  • 1 ≤ elements.length ≤ 10^5
  • 1 ≤ elements[i] ≤ 10^5

Source note: The extra source frames show the long return type, the limits, and a second example. The November 5 photo is blurry; its limits for n and elements[i] look larger, but the digits are hard to read. The clear frames show 10^5 for both, which this page uses.

More Microsoft Online Assessment questions

  • Authentication SystemOA · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Minimum Distinct Prefix CostChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Longest String ChainVisa · OAVisa interview questions
  • Convert Sparse Records to a Filled TableNetflix · OANetflix interview questions
  • Maximum Points by Deleting ElementsWalmart · OAWalmart interview questions
  • Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
  • Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
  • Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions

Interview reports that mention this question

  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long maxEscapeGameScore(int[] elements) {
      // Write your code here.
    }
}
Checking account…