Code Room
CodingEasycod-g1288
Subject HeapsLevel Entry–Mid~13 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

An imaging suite runs scans back to back in the exact order they were booked. Each scan occupies one time slot. The machine needs `gap` idle slots between two scans of the same type (different types can run back to back); the schedule waits, leaving slots empty, whenever the rule requires. Given the ordered list of scan types and the integer gap, return the total number of slots from the start until the last scan finishes. Example: scans = ["MRI", "MRI"], gap = 2 gives 4 — the second MRI waits out slots 1 and 2 and runs in slot 3.

Implement
schedule_length(scans: list[str], gap: int) → int
Examples
in[["MRI","MRI"],2]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.