As reported: Rippling SDE intern (on-campus, Bangalore, Oct 2026, selected), round 1 (DSA), in Java: design an in-memory task scheduler that supports insert, delete, and execute by priority. Follow-ups: tasks with equal priority, optimizing the complexity, and scaling to millions of tasks.
Design TaskScheduler:
addTask(taskId, priority)— add a pending task. A largerprioritynumber means more important.removeTask(taskId)— delete the pending task with this id; returntrueif there was one,falseotherwise.executeNext()— remove and return the id of the task to run next: the highest priority, and among equal priorities the one added earliest. Return-1if no task is pending.
Example
addTask(1, 5)
addTask(2, 9)
addTask(3, 5)
executeNext() → 2
removeTask(1) → true
removeTask(1) → false
executeNext() → 3
executeNext() → -1
Constraints: at most 2·10^5 calls; 1 ≤ taskId ≤ 10^9, 1 ≤ priority ≤ 10^9; a task id is never added while a task with the same id is pending (it may be added again after it was executed or removed — it then counts as newly added).
Code runner format: one call per line — ADD id priority, REMOVE id, EXECUTE — and the harness prints the result of every REMOVE and EXECUTE. Implement the class with the three methods (in Go: NewTaskScheduler() and exported method names).
Follow-ups
- Tasks with equal priority (here: first added, first run).
- Optimize the complexity of each operation.
- Scale to millions of tasks.