Assign Exam Batches to Test Center Labs With Sanitization Gaps

Last updated: November 29, 2026

Quick Overview

A test center runs exam batches as (batch_id, start, end) in minutes, and each lab needs a fixed cleanup and system reset gap after a batch before the next can start; return the minimum number of labs and a lab assignment for every batch.

TCS
Coding & Algorithms
Software Engineer
TCS
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


A test center runs exam batches as (batch_id, start, end) in minutes, and each lab needs a fixed cleanup and system reset gap after a batch before the next can start; return the minimum number of labs and a lab assignment for every batch.

TCS iON schedules many shifts of a single exam across its secure test centers, and lab planning is a natural scheduling problem in a coding assessment. The interviewer checks that the candidate reaches the greedy heap solution, handles the gap correctly, and can argue it is optimal.

What the Interviewer Expects
  • Sort batches by start time
  • Use a min-heap of times at which labs become free
  • Reuse the earliest free lab, otherwise open a new one
  • Add the gap to the end time when pushing back
  • Argue optimality via maximum overlap
Key Topics to Cover
Interval partitioning
Greedy
Min-heap
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
  • How would you also minimize the number of distinct labs each invigilator walks between?
  • What if labs have different seat capacities and batches have sizes?
  • How do you produce the answer if only the count is needed, in O(N log N) without a heap?
  • How would you handle a batch overrunning its end time on the day?
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

A lab that hosts a batch ending at e is ready again at e + gap. A batch starting exactly at the ready time may use it. Return the lab count and a map from batch to lab index....

High-Level Design

Classic interval partitioning with the gap folded into each interval's end. Process batches by start time and keep a min-heap keyed by ready time. If the earliest-ready lab is free by this start, reus...


Submit Your Answer
Markdown supported

Related Questions