FastPrepPriority Queue Class
Problems/Priority Queue Class

Priority Queue Class

Nutanix logoNutanix● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This is a Nutanix intern candidate's account of a technical phone interview. An HR screen and a referral came before it. According to the report, the phone round had one coding task, which we read as a priority queue, followed by a complexity discussion.

The report also makes a brief remark about enqueue and the priority. Its meaning is unclear, so it is not used here, and every enqueue gives a priority. The report gives no method signatures, no rule for equal priorities or for an empty queue, no limits and no examples. Here we also chose the following. Equal priorities leave in the order they arrived. Dequeue on an empty queue returns -1. The calls arrive as a list of operations. There are up to 2000 calls with values and priorities from 0 to 10^6. The examples are ours.

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

Implement a class PriorityQueue in which every value waits with a priority:

  • void enqueue(int value, int priority) adds value with the given priority.
  • int dequeue() removes and returns the waiting value with the highest priority. If several waiting values share that priority, the one that was added earliest leaves first. If the queue is empty, return -1.

To test your class, you get operations, the calls made in order on one new queue, and operands, the arguments of each call. Return one string per call: "null" for enqueue, and the returned number in normal decimal form for dequeue.

Function

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

Examples

Example 1

operations = ["enqueue","enqueue","enqueue","dequeue","dequeue","dequeue"]operands = [[10,2],[20,7],[30,5],[],[],[]]return = ["null","null","null","20","30","10"]

The queue holds 10 (priority 2), 20 (priority 7) and 30 (priority 5). The highest priority is 7, so the first dequeue returns "20". Then 30 (priority 5) leaves, and finally 10 (priority 2).

Example 2

operations = ["enqueue","enqueue","enqueue","dequeue","dequeue","dequeue"]operands = [[4,3],[8,3],[6,9],[],[],[]]return = ["null","null","null","6","4","8"]

6 has the highest priority, 9, so it leaves first. 4 and 8 both have priority 3; 4 was added earlier, so it leaves before 8.

Example 3

operations = ["dequeue","enqueue","dequeue","dequeue"]operands = [[],[5,0],[],[]]return = ["-1","null","5","-1"]

The first dequeue finds the queue empty and returns "-1". After 5 is added, dequeue returns "5", and the last dequeue again finds the queue empty.

Constraints

  • 1 <= operations.length <= 2000 and operands.length == operations.length
  • Each operation is "enqueue" or "dequeue".
  • operands[i] is [value, priority] for enqueue and [] for dequeue.
  • 0 <= value, priority <= 10^6

More Nutanix Phone Screen questions

  • Swap Adjacent Linked List NodesPHONE SCREEN · Seen Mar 2025
  • Top K Most Frequent ValuesPHONE SCREEN · Seen Mar 2025
  • Unique Triplets Summing to ZeroPHONE SCREEN · Seen Sep 2024
  • Find the Duplicate in a Read-Only ArrayPHONE SCREEN · Seen Apr 2021
  • Kth Largest Element in an ArrayPHONE SCREEN · Seen Feb 2020
  • Kth Smallest Element in a BSTPHONE SCREEN · Seen Feb 2020
  • Outline of a Binary TreePHONE SCREEN · Seen Jan 2020
  • Print All File and Folder PathsPHONE SCREEN · Seen Dec 2019
  • Inorder Predecessor in a BSTPHONE SCREEN · Seen Jan 2019
  • K Largest and K Smallest ValuesPHONE SCREEN · Seen Jan 2019

Similar questions at other companies

  • Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • Per-Client API Rate LimiterDocker · PHONE SCREEN
  • Streaming Median of Trade PricesXantium · PHONE SCREEN
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Rolling Hit CounterDatabricks · PHONE SCREENDatabricks interview questions
  • Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
  • VIP and Regular Service SchedulerIntuit · PHONE SCREENIntuit interview questions

Interview reports that mention this question

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)

Nutanix interview experiences

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public String[] runPriorityQueue(String[] operations, int[][] operands) {
        // Write your code here.
    }
}
Checking account…