Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Tiered Task Queue Scheduler

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Tiered Task Queue Scheduler. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Design a task queue that supports prioritized scheduling by user tier. Implement a function that processes a list of operations on tasks, where each task has a unique task_id, a tier, and an insertion order. Higher tiers must be served before lower tiers, and tasks within the same tier must be served in first-in-first-out order. Support enqueue, dequeue, and cancel by task_id, returning the results of dequeue operations.

Constraints

  • 1 <= len(operations) <= 2 * 10^5
  • 1 <= tier <= 10^9
  • task_id is a non-empty string and is unique across active tasks
  • Operations are one of enqueue, dequeue, or cancel
  • cancel may reference an already removed or nonexistent task

Function Signature

def process_task_queue(operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output