Maximize Points by Deleting Values and Their Neighbors
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Maximize the score from removing integer occurrences when each choice also removes neighboring values, with duplicates and a sparse value range.
Read the full Microsoft Software Engineer interview experience this question came from
Constraints
- 1 <= nums.length <= 20000 and 1 <= nums[i] <= 1000000000; duplicate values and large gaps are allowed.
- Selecting one occurrence of v earns v points and removes all remaining occurrences of v-1 and v+1 without earning their points.
- Other occurrences of v remain available for later selections. Conflicts depend on values, not input positions.
- Return only the exact maximum score; it can be as large as 20000000000000 and need not fit in a signed 32-bit integer.
Examples
Input: ([2, 2, 3, 3, 3, 4],)
Expected Output: 9
Explanation: Published sample 1: all three copies of 3 earn nine, beating the two copies of 2 plus 4.
Input: ([1, 1, 3, 1000000000],)
Expected Output: 1000000005
Explanation: Published sample 2: no present distinct values are consecutive, so every occurrence contributes.