Maximum Score from Deleting Neighboring Values
Updated
Problem statement
You may repeatedly choose an occurrence of a value x from nums. Remove that occurrence and earn x points. The same move removes every remaining occurrence of x-1 and x+1 for zero points. Other copies of x remain available for later moves.
Return the largest total score achievable. You may stop at any time. For this exercise, assume all values are nonnegative and an empty array earns zero. Use a 64-bit integer result.
Function
maximumDeletionScore(nums: int[]) → longExamples
Example 1
nums = [3,4,2]return = 6Choose 4 to earn 4 and remove 3, then choose 2 to earn 2. Total 6 beats choosing 3.
Example 2
nums = [2,2,3,3,3,4]return = 9Choose all three copies of 3 for 9 points. The first choice removes the 2 and 4 copies for zero.
Constraints
- For this exercise, assume
0 <= nums.length <= 20000. 0 <= nums[i] <= 10^9.
More PeopleStrong Phone Screen questions
- Reverse Linked-List Nodes in Groups of KOA · PHONE SCREEN · Seen Mar 2026
- Level of the Minimum-Sum SubtreePHONE SCREEN · Seen Jan 2026
- Ceiling Value in a Sorted ArrayPHONE SCREEN · Seen Sep 2025
- Maximum Employee Salary for a CompanyPHONE SCREEN · Seen Sep 2025
- Valid ParenthesesPHONE SCREEN · Seen Sep 2025
- Number of ProvincesPHONE SCREEN · Seen May 2025
- Shortest Subarray with an Exact Target SumPHONE SCREEN · Seen May 2025
- Add Forward Linked-List Numbers Using RecursionPHONE SCREEN · Seen Oct 2021
- Running Median of a StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2021
- Build an Expression Tree from PostfixPHONE SCREEN · Seen Oct 2021
Similar questions at other companies
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Longest String ChainVisa · OAVisa interview questions
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesStripe · PHONE SCREENStripe interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Minimum Total Layover WaitGoogle · PHONE SCREENGoogle interview questions
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Group AnagramsWorkday · PHONE SCREEN