FastPrepMaximum Points by Deleting Elements
Problems/Maximum Points by Deleting Elements

Maximum Points by Deleting Elements

Walmart logoWalmart● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source image provides the maxPoints signature, return type, exact bounds, and the [3,4,2] example; the caption supplies the repeated deletion rule and value-frequency insight. The original screenshot contains redactions and an account watermark across task pixels, so it is retained as evidence rather than displayed. The judged core task matches the report at about 97%.

You are given an integer array elements. Repeatedly choose one remaining element with value x and earn x points. The chosen element is removed, and every remaining element equal to x - 1 or x + 1 is deleted.

Continue until no elements remain. Return the maximum total number of points you can earn.

Function

maxPoints(elements: int[]) → long

Examples

Example 1

elements = [3,4,2]return = 6

Choose 4 to earn 4 points, which deletes the neighboring value 3. Then choose 2 to earn 2 more points. The total is 4 + 2 = 6.

Constraints

  • 1 <= elements.length <= 10^5.
  • 1 <= elements[i] <= 10^5 for every valid index i.

More Walmart problems

  • Merge a List In Between Two PositionsONSITE INTERVIEW · Seen Nov 2026
  • Merge Intervals from Start and End ListsONSITE INTERVIEW · Seen Nov 2026
  • Palindrome Check Ignoring SymbolsONSITE INTERVIEW · Seen Nov 2026
All Walmart interview questionsSee Walmart hiring insights
Saved
class Solution {
    public long maxPoints(int[] elements) {
        // write your code here
    }

}
Checking account…