Find go-live hours that meet every gap rule
Your task
A new version of your support agent goes live one customer group at a time. The on-call team sets gap rules between groups. A soak rule leaves one group time to show problems before another goes live. A coverage rule keeps two go-lives close together, because the support team booked for both is only around for so long.
Write go_live(n, rules) that returns the earliest hour each group can go live.
Input and output:
n: the number of groups, 1 to 300. Groups are numbered 0 ton - 1.rules: 0 to 3,000 rules, each[a, b, kind, h].aandbare two different groups,kindis"after"or"within", andhis a whole number of hours from 0 to 1,000,000. The same pair may appear in several rules.- Return a list of
nwhole numbers, the go-live hour of each group in order. Return an empty list when no plan meets every rule.
Rules:
"after": groupbgoes live at leasthhours after groupa."within": groupbgoes live at mosthhours after groupa. This rule never stopsbfrom going live beforea.- Every group goes live at hour 0 or later. Several groups may go live in the same hour.
- Return each group's earliest hour over all plans that meet every rule. Those hours, taken together, also meet every rule.
Examples
go_live(n: int, rules: list[list]) -> list[int]Example 1
Input
go_live(3, [[0, 1, "after", 4], [1, 2, "after", 2]])Output
[0, 4, 6]Example 2
Input
go_live(3, [[0, 1, "after", 10], [2, 1, "within", 3]])Output
[0, 10, 7]Example 3
Input
go_live(2, [[0, 1, "after", 5], [0, 1, "within", 3]])Output
[]