Maximize Order Points When Picking a Value Removes Its Neighbors
Last updated: November 29, 2026
Quick Overview
You earn v points each time you pick an order worth v, but picking it deletes every order worth v-1 or v+1 from the pool. Return the maximum total points you can earn.
Amazon
November 29, 20260
0
0 solved
You earn v points each time you pick an order worth v, but picking it deletes every order worth v-1 or v+1 from the pool. Return the maximum total points you can earn.
This tests reduction to a known DP: bucket by value, then it becomes the no-adjacent-picks problem. Interviewers at Amazon like questions where the main skill is seeing the reduction and explaining it clearly before writing code.
What the Interviewer Expects
- Realize picking a value once means taking all copies of it
- Bucket total points by value
- Apply the no-adjacent-values DP over the value range
- Handle sparse large values by sorting distinct values
- O(n + V) or O(n log n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if values go up to 10^9?
- What if picking v deletes v-2 through v+2?
- How would you return which values were picked?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of positive integers. Each pick earns the value and removes all v-1 and v+1 copies. Output: maximum total points....
High-Level Design
If you pick one order worth v, the other v copies are unaffected (only v-1 and v+1 vanish), so you will pick all of them. So the decision is per value: take value v and earn earn[v] = v * count[v], ...