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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

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
Min-Heap
Simulation
Sorting
Scheduling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported