Order Requests Processed by a Single-Threaded Borg Worker
Last updated: November 29, 2026
Quick Overview
Each task has an enqueue time and a processing time. A single-threaded worker, when idle, picks the available task with the shortest processing time (ties by lower index) and runs it to completion. Return the order of task indices it processes.
0
0
0 solved
Each task has an enqueue time and a processing time. A single-threaded worker, when idle, picks the available task with the shortest processing time (ties by lower index) and runs it to completion. Return the order of task indices it processes.
A Google onsite event simulation in a cluster scheduler frame. The interviewer checks sorting by arrival, a min-heap keyed by (duration, index), and correct handling of idle gaps where the clock must jump forward.
What the Interviewer Expects
- Sorts tasks by enqueue time keeping indices
- Uses a min-heap keyed on (processing time, index)
- Jumps the clock when the worker is idle
- Processes each task exactly once
- States O(n log n)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Add k worker threads
- Add preemption when a shorter task arrives
- Report average waiting time
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
tasks[i] = (enqueue_time, processing_time). - The worker starts idle at time 0. When idle with available tasks, it picks the shortest, ties broken by smaller index.
- If nothing is availabl...
High-Level Design
Sort task indices by enqueue time so arrivals can be swept with a pointer. Maintain time and a min-heap of (processing_time, index) for tasks that have arrived but not run.
Loop: if the heap is e...