FastPrepImplement a Min-Priority Queue
Problems/Implement a Min-Priority Queue

Implement a Min-Priority Queue

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time onsite interview. The report asks you to build a priority queue by hand. We use a finite list of min-queue operations, with insert, peek, remove, valid reads, and duplicate values. This is the smallest usual way to make the answer fixed. Our version is about 86% the same as the reported question.

Implement a min-priority queue of integers without using a built-in priority-queue or heap data structure. Process operations from left to right. For the operation at index i:

  • PUSH inserts values[i].
  • PEEK returns the current minimum without removing it.
  • POP removes and returns the current minimum.

Return every value that PEEK or POP returns, in the order the operations run. Every PEEK and POP happens while the queue is nonempty. Equal values are allowed. For PEEK and POP, values[i] is ignored.

Function

runPriorityQueue(operations: String[], values: int[]) → int[]

Examples

Example 1

operations = ["PUSH","PUSH","PEEK","POP","PEEK"]values = [5,2,0,0,0]return = [2,2,5]

After both insertions, the minimum is 2, so PEEK returns 2 without removing it. POP then removes and returns that same value. Only 5 is left, so the last PEEK returns it. The answer lists the returned values in that order.

Example 2

operations = ["PUSH","PUSH","PUSH","POP","POP","POP"]values = [3,3,1,0,0,0]return = [1,3,3]

The pushes insert the values three, three, and one. The two threes stay separate entries in the queue. The first POP removes one, the minimum. The next two POP operations each remove a three. The answer is one, then three, then three.

Example 3

operations = ["PUSH","PEEK","PUSH","PEEK"]values = [-4,0,-7,0]return = [-4,-7]

The first push inserts minus four. It is the only value, so the first PEEK returns minus four. The second push inserts minus seven, which is smaller and becomes the new minimum. The last PEEK returns minus seven. The answer is minus four, then minus seven.

Constraints

  • 1 <= operations.length == values.length <= 200000.
  • Each operation is PUSH, PEEK, or POP.
  • Every PEEK and POP occurs when the queue is nonempty.
  • Each inserted value is a signed 32-bit integer.

More Amazon Onsite Interview questions

  • Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Flood FillONSITE INTERVIEW · Seen Nov 2026
  • Merge k Sorted ListsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Delayed Job SchedulerWalmart Labs · ONSITE INTERVIEW
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Priority Job Scheduler with CooldownsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Order Matching EngineJane Street · ONSITE INTERVIEWJane Street interview questions
  • Trip Booking with the Earliest Free DriverRippling · ONSITE INTERVIEWRippling interview questions
  • Reusable Number AllocatorDropbox · ONSITE INTERVIEWDropbox interview questions

Interview reports that mention this question

  • Amazon Experienced Hire OA and Interviews: 21 Experiences

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)
See Amazon hiring insights
Saved
class Solution {
    public int[] runPriorityQueue(String[] operations, int[] values) {
      // write your code here
    }
}
Checking account…