FastPrepCancellable Priority Task Queue
Problems/Cancellable Priority Task Queue

Cancellable Priority Task Queue

Citadel logoCitadel● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel intern onsite interview. The report describes adding, deleting, and running tasks using a priority queue with lazy deletion. It leaves out the ordering, replacement, what happens when empty, the limits, and the interfaces. We chose those rules. Our version is about 80% the same as the reported question.

Process operations on an initially empty task queue:

  • [0,id,priority]: insert a task. If the id is active, replace it. Every insertion receives a new increasing insertion sequence.
  • [1,id,0]: delete the active task with that id, if any.
  • [2,0,0]: execute and remove the active task with greatest priority. Break equal-priority ties by earliest insertion sequence. Return its id, or -1 if empty.

Return only execution results, in operation order. A replacement loses the old insertion sequence, even when its priority is unchanged.

Function

runPriorityTasks(operations: int[][]) → int[]

Examples

Example 1

operations = [[0,7,4],[0,8,4],[0,9,6],[1,9,0],[2,0,0],[2,0,0],[2,0,0]]return = [7,8,-1]

Task 9 is deleted before execution. Tasks 7 and 8 have equal priority, so 7 executes first because it was inserted earlier. The third execution finds an empty queue.

Example 2

operations = [[0,1,5],[0,2,5],[0,1,5],[2,0,0],[2,0,0]]return = [2,1]

Replacing task 1 gives it a new insertion sequence after task 2. Task 2 therefore wins the equal-priority tie.

Constraints

  • 0 <= operations.length <= 100000.
  • Every operation contains exactly three integers.
  • -10^9 <= operations[i][j] <= 10^9.
  • Operation codes are 0, 1, or 2; ids are nonnegative; deletion has a final zero; execution has two final zeros.

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
  • Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
  • Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026
  • Dynamic Weighted SamplingONSITE INTERVIEW · Seen Jan 2026
  • Exchange Connection AlertsONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Lowest-Bid Auction SystemGoogle · ONSITE INTERVIEWGoogle interview questions
  • Mutable Stock Price Top KBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • 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
  • Highest-Earning Experience TrackerRoblox · ONSITE INTERVIEWRoblox interview questions
  • Mean, Median and Mode of a StreamMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions

Interview reports that mention this question

  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[] runPriorityTasks(int[][] operations) {
        // Write your code here.
    }
}
Checking account…