Keyed Bounded Executor Schedule
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
With n up to 100000, a naive rescan of every waiting task at each event will time out, and that's the wall in this Microsoft OA reported in September 2026. It's a simulation: tasks all arrive at time 0, a concurrency cap limits how many run, and each key can only have one active task at a time. The trick is event-driven time with a min-heap of completions plus smart tracking of which task is next per key. If you blank on the structure mid-assessment, StealthCoder runs invisibly as a safety net while you're live.
The problem
All tasks are submitted at time 0 in input order. Task i has key keys[i] and runs for durations[i] time units. Build the deterministic schedule produced by these rules: At most maxConcurrent tasks run at once. Tasks with the same key run in submission order and never overlap. Whenever capacity is available, start the smallest-index waiting task whose key is not active. If no task can start, advance time to the next completion. All tasks ending at that time release their keys before new tasks start. Return [startTime, endTime] for every task in original input order. Function scheduleKeyedTasks(keys: String[], durations: int[], maxConcurrent: int) → long[][] Examples Example 1 keys = ["a","b","a","c"] durations = [4,3,2,1] maxConcurrent = 2 return = [[0,4],[0,3],[4,6],[3,4]] Tasks 0 and 1 start first. At time 3 task 2 is still blocked by key a, so task 3 uses the free slot. Example 2 keys = ["x","x","y"] durations = [1,1,5] maxConcurrent = 3 return = [[0,1],[1,2],[0,5]] Extra global capacity cannot make the two x tasks overlap. Constraints 1 <= keys.length = durations.length <= 100000. 1 <= maxConcurrent <= keys.length. Keys are nonempty printable ASCII strings. 1 <= durations[i] <= 1000000. Every returned time fits a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Group task indices by key into queues, so only the head of each key's queue is ever eligible. Keep a min-heap of eligible heads ordered by index, and a min-heap of running tasks ordered by end time. Loop: while running count is below maxConcurrent and the eligible heap is nonempty, pop the smallest index, set start to current time, end to start plus duration, and push to the running heap. When nothing can start, jump time to the next end time, pop every task ending at that time, release their keys, and push each key's next queued task into the eligible heap. The pitfall is releasing only one task at a tie instead of all of them before starting new ones. Another is rescanning waiting tasks each step, which is O(n^2). Use long for times. Total work is O(n log n). StealthCoder is the hedge if the two-heap bookkeeping slips under pressure.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Keyed Bounded Executor Schedule cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Keyed Bounded Executor Schedule FAQ
What's the trick in this Microsoft keyed executor problem?+
Don't scan all waiting tasks. Queue tasks per key so only each key's head is eligible, then use a min-heap of eligible indices and a min-heap of running end times. Jump time between completions instead of ticking.
How hard is this really?+
Medium-hard. The rules are simple but easy to get subtly wrong. The tie handling at completion and the smallest-index rule trip people up more than the data structures do.
Why can't I just brute force it?+
With up to 100000 tasks, rescanning every waiting task at each event is quadratic and will likely time out. The heaps bring it to O(n log n), which fits the constraints comfortably.
Do I need 64-bit integers?+
Yes. Durations go up to 1000000 across 100000 tasks, so a single key chain can exceed 32-bit range. Use long for start and end times and the current clock.
How do I prepare in 48 hours?+
Practice event-driven simulations with two heaps, like meeting rooms and task schedulers. Hand-trace both examples, especially the time 3 case where task 2 is blocked by key a but task 3 starts. Then code it cleanly with the all-endings-release-first step.