Priority Message Buffer
Updated
Problem statement
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:
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.
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
$99 billed yearly — or $19 month-to-month. Cancel anytime.
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)