FastPrepAPI Call Thread Pool Schedule
Problems/API Call Thread Pool Schedule

API Call Thread Pool Schedule

Baseten logoBaseten● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Baseten full-time onsite interview. The report asks the candidate to replace a loop of API calls, run one after another, with a thread pool that runs. It leaves out the request model, the pool size, failures, and the order of results. Here we use a made-up clock so the same limited-worker scheduling can be tested.

You are given API calls in submission order. Call i takes durations[i] units of time and occupies one worker for its entire duration. A fixed thread pool contains workers labeled from 0 through workerCount - 1.

Dispatch calls in input order. Assign each call to the worker with the earliest available time; if several workers are available at the same time, choose the smallest worker ID. The call starts at that worker's current available time and ends after its duration. A worker becomes available immediately at the end time.

Return one row [workerId, startTime, endTime] for every call, in original input order.

Function

scheduleApiCalls(durations: int[], workerCount: int) → int[][]

Examples

Example 1

durations = [5, 2, 4, 1]workerCount = 2return = [[0, 0, 5], [1, 0, 2], [1, 2, 6], [0, 5, 6]]

The first two calls occupy both workers. Worker 1 finishes first and receives call 2; worker 0 then becomes available before worker 1 and receives call 3.

Example 2

durations = [3, 3, 3, 3, 3]workerCount = 3return = [[0, 0, 3], [1, 0, 3], [2, 0, 3], [0, 3, 6], [1, 3, 6]]

All three workers tie at time 0 and later at time 3, so worker IDs break both ties.

Example 3

durations = [4, 1]workerCount = 4return = [[0, 0, 4], [1, 0, 1]]

There are more workers than calls, so both calls start immediately on the two smallest worker IDs.

Constraints

  • 1 <= durations.length <= 100000
  • 1 <= workerCount <= 100000
  • 1 <= durations[i] <= 10^9
  • Every start and end time fits a signed 32-bit integer.

More Baseten interview questions

  • Single-Pass S-Expression ParserONSITE INTERVIEW · Seen Nov 2026
  • RNG-Based Tree Document CodecPHONE SCREEN · Seen Oct 2026
  • XOR Pseudorandom SequencePHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Ad Rotation Scheduler With CooldownGoogle · ONSITE INTERVIEWGoogle interview questions
  • Assign Partitions to the Least-Loaded ServersAmazon · ONSITE INTERVIEW
  • Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Combine the Two Smallest Until All Reach kAdobe · PHONE SCREENAdobe interview questions
  • Initial Public OfferingPoint72 · OAPoint72 interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Delayed Job SchedulerWalmart Labs · ONSITE INTERVIEW
  • UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEWWayfair interview questions

Baseten interview experiences

  • Baseten Experienced MLE Onsite: 1 Experience
All Baseten interview questionsSee Baseten hiring insights
Saved
class Solution {
    public int[][] scheduleApiCalls(int[] durations, int workerCount) {
      // write your code here
    }
}
Checking account…