Scan schedule with gaps

Write codeEasy13 min

Your task

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.

Examples

schedule_length(scans: list[str], gap: int) -> int
Example 1
Inputschedule_length(["MRI", "MRI"], 2)
Output4