Dynamic Batch Completion Times

Reported by candidates from Ambience Healthcare's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Ambience Healthcare OA. Under 2s to a working solution.
Founder's read

Ambience Healthcare reported this one in September 2026, and it looks like a scheduling story but it's really a min-heap problem wearing a costume. You've got sequences waiting in order, a fixed number of slots, and you need each finish time. If you've got an OA coming up, this is the shape to recognize: always grab the slot that frees up first. It's short once you see it. If you blank on the heap setup during the live assessment, StealthCoder is the invisible backup that reads the problem and hands you a working solution.

The problem

All generation sequences are waiting at time 0 in input order. A dynamic batch has batchSize identical slots. A sequence of length L occupies one slot for L time units.
Whenever a slot becomes free, immediately assign the next waiting sequence. If several slots become free together, use the smaller slot index first. Return each sequence's completion time in input order.

Function
dynamicBatchCompletionTimes(sequenceLengths: int[], batchSize: int) → int[]

Examples
Example 1
sequenceLengths = [2,1,3]
batchSize = 2
return = [2,1,4]
The length-1 sequence finishes first; the third sequence immediately takes that slot.
Example 2
sequenceLengths = [3,3,3]
batchSize = 1
return = [3,6,9]
One slot processes every sequence serially.
Example 3
sequenceLengths = [1,1,1,1]
batchSize = 2
return = [1,1,2,2]
Two sequences finish at each time step.

Constraints
1 <= sequenceLengths.length <= 100000.
1 <= batchSize <= sequenceLengths.length.
1 <= sequenceLengths[i] <= 100000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: track when each slot becomes free in a min-heap. Seed it with batchSize slots, each as (freeTime 0, slotIndex). For each sequence in input order, pop the smallest (freeTime, index), compute finish = freeTime + length, store finish in the answer at that sequence's position, then push (finish, index) back. The tuple ordering handles the tie rule, since equal free times fall back to the smaller slot index. The common pitfall is sorting sequences or reordering by length. Don't. Assignment order is fixed by input, only slot choice is dynamic. Another pitfall is forgetting the tiebreak, which matters for correctness in the spec even if the output times look the same. Complexity is O(n log k) with n up to 100000, so a naive scan of all slots per sequence is risky when batchSize is large. If the heap logic slips under pressure, StealthCoder works as the safety net during the live OA.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Dynamic Batch Completion Times 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Ambience Healthcare's OA.

Ambience Healthcare reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Dynamic Batch Completion Times FAQ

What's the core trick in Dynamic Batch Completion Times?+

Use a min-heap of slot free times. Pop the earliest free slot, add the sequence length to get its completion time, record it by input index, and push the slot back with the new free time. Repeat for every sequence in order.

Does the slot index tiebreak actually change the answer?+

Completion times for each sequence come out the same regardless, since slots are identical. Still, storing (freeTime, slotIndex) in the heap follows the spec exactly and costs nothing. It keeps your solution faithful if a hidden test checks assignment behavior.

What complexity should I aim for with these constraints?+

O(n log k), where n is the number of sequences and k is batchSize. With n up to 100000, an O(n*k) scan across all slots can blow up when batchSize is near n. The heap keeps it fast and simple.

Should I sort the sequences to finish faster?+

No. Sequences are assigned in input order, and the output must match input positions. Sorting changes who gets which slot and breaks the expected results like [2,1,4] in Example 1. Only the slot choice is dynamic.

How do I prepare for this in 48 hours?+

Write the heap simulation from scratch twice. Trace Example 1 and Example 3 by hand to confirm ties behave. Practice your language's priority queue syntax, especially tuple ordering, since that's where candidates lose minutes on the Ambience Healthcare style of problem.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Ambience Healthcare.

OA at Ambience Healthcare?
Invisible during screen share
Get it