FastPrepPriority Message Buffer
Problems/Priority Message Buffer

Priority Message Buffer

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionExamples

Problem statement

Source note: Reported as the third round of an Amazon onsite interview for a full-time software engineering role. The report describes the task briefly: a buffer limited by the total size of its messages, where every message has a size and either a high or a low priority. When a new message does not fit, low priority messages make room before high priority ones. A drain operation with a size limit takes messages out of a queue.

The report gives no interface, no examples and no limits, so every rule that changes an answer beyond those is our assumption: (a) inside one priority, the oldest message is evicted first; (b) a message larger than the whole capacity is dropped at once and evicts nothing; (c) a low priority push may also evict high priority messages once no low priority message is left, which is how we read the report's order of low first, then high; (d) one queue holds both priorities in arrival order, and a drain takes from its front. The report's wording on where a drain stops can be read two ways: just before the message that would take the drained total over the limit, or only after the total has gone over it. We chose the first, so the drained total never passes the limit and that message stays in the buffer. The input and output are ours too: the operations are text strings run in order; a push returns the ids it evicted in eviction order, or a list with only its own id when the message is dropped; a drain returns the ids it took in order; a total equal to the capacity fits; ids are never reused; the limits and all the examples are ours. The other coding rounds and the system design round of the same interview are not part of this problem.

Our version is about 70% the same as the reported question.

Given the capacity of a message buffer and a list of operations on it, run the operations in order and return one list of message ids for each operation.

Each message has an id, a priority, which is HIGH or LOW, and a size. The total size of the messages in the buffer must never be more than capacity. The buffer keeps all its messages, of both priorities, in one queue in the order they arrived.

Each string in operations has one of these two forms, with parts separated by single spaces:

The problem statement continues
Pro

Examples

Example 1

capacity = 10operations = ["PUSH a HIGH 4","PUSH b LOW 3","PUSH c LOW 2","PUSH d HIGH 4","DRAIN 7"]return = [[],[],[],["b"],["a","c"]]

Adding d would bring the total to 13, which is over 10. The oldest low priority message, b, is evicted, and the total of 10 fits. DRAIN 7 takes a and c (total 6) and stops, because d would bring the total to 10.

02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

More Amazon Onsite Interview questions

  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Concurrent Buffered File LoggerDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Article Vote TrackerRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Weighted Round-Robin Seller Task SchedulerByteDance · ONSITE INTERVIEWByteDance interview questions
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Matching Engine with Order CancellationIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week