Minimum Concurrent Batch Slots to Meet a Nightly Deadline

Last updated: November 29, 2026

Quick Overview

Batch jobs arrive at given times with known durations and are dispatched first-come first-served to whichever of k worker slots frees up earliest. Return the smallest k such that every job finishes by a deadline, or -1 if no k works.

Salesforce
Coding & Algorithms
Software Engineer
Salesforce
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Batch jobs arrive at given times with known durations and are dispatched first-come first-served to whichever of k worker slots frees up earliest. Return the smallest k such that every job finishes by a deadline, or -1 if no k works.

Salesforce runs large volumes of asynchronous work (Batch Apex, data loads, nightly Data Cloud refreshes) under per-org concurrency caps, and capacity planning for these queues is a real platform concern. The interviewer is looking for the binary-search-on-answer pattern, a correct heap simulation as the feasibility check, and a convincing argument that feasibility is monotonic in k.

What the Interviewer Expects
  • Identify that a direct formula is hard but checking a given k is easy by simulation
  • Simulate FIFO dispatch with a min-heap of slot free times
  • Argue monotonicity: more slots never make any job start later
  • Handle the impossible case where a single job alone misses the deadline
  • State O(n log n log n) total time
Key Topics to Cover
binary search on answer
min-heap
simulation
scheduling
monotonicity
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
  • Jobs now have priorities and the dispatcher picks the highest-priority waiting job. Does monotonicity still hold?
  • How would you find the earliest achievable deadline for a fixed k?
  • How would you handle jobs whose durations are estimates with variance?
  • If slots cost money per hour of uptime, how would you change the objective?
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: jobs as (arrival, duration) with duration > 0, and deadline. Dispatch is FIFO by arrival: each job goes to the slot that frees earliest and starts at max(arrival, free_time). Return the...

High-Level Design

finishes_by(k) simulates with a min-heap of k free times. Monotonicity: by induction over jobs in FIFO order, the sorted free times with k+1 slots are pointwise no later than with k slots, so each j...


Submit Your Answer
Markdown supported

Related Questions