Support roster rotations

Write codeEasy16 min

Your task

A support roster is filled one night at a time. engineer_teams[i] names the team engineer i belongs to, and the run has shifts consecutive nights. A rotation names one engineer per night, so two rotations differ as soon as any single night differs. Two rules apply: consecutive nights must go to engineers from different teams, since a team that just handed off needs the night to recover, and no engineer may cover more than max_shifts nights across the whole run. Return how many rotations satisfy both rules. A run of zero nights has exactly one rotation, the empty one, so return 1 there. The roster holds at most 5 engineers and the run is at most 7 nights.

Examples

count_oncall_rotations(engineer_teams: list[str], shifts: int, max_shifts: int) -> int
Example 1
Inputcount_oncall_rotations(["core", "core", "edge"], 2, 2)
Output4
Example 2
Inputcount_oncall_rotations(["core", "edge"], 3, 2)
Output2
Example 3
Inputcount_oncall_rotations(["ops"], 1, 1)
Output1