Hardware interview practice
Verify a time-slotted capacity checker
Write a difference-array oracle for one to sixteen reservations over 32 time slots, returning format status, feasibility, global peak load, and the earliest slot above capacity.
Reviewed example
Work through one case
Input
capacity=3; reservations=[(start=0,end=4,units=2),(start=2,end=5,units=2)]Expected output
feasible=0; global_peak=4; first_bad_slot=2The half-open intervals overlap at slots 2 and 3, producing load four; slot 2 is the first strictly above capacity.
What to cover
Requirements
- Accept an already assembled reservation list plus a framing-valid flag; classify zero units, start not less than end, end above 32, or a list outside 1 through 16 as format_error.
- For valid half-open intervals, sweep signed deltas across all 32 slots, retain the global peak, and record only the first load strictly greater than capacity.
- A feasible result has first_bad_slot zero; a format error has feasible zero and all numeric result fields zero.
- Treat frame monitoring, four-ID response matching, reset epochs, and coverage as follow-up scoreboard work.
