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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
1D dynamic programming
problem reduction
bucketing
house robber pattern
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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], ...


Submit Your Answer
Markdown supported