Release train waves

Write codeEasy16 min

Your task

A release train rolls a fleet out in waves. Every service in a wave goes out together, and a service may join a wave only once every service it depends on has already gone out in an earlier wave. services lists every service name, and each entry in edges is a string like "db>api", meaning db must be deployed before api. Both names in an entry always appear in services. Put every service in the earliest wave it can join. Return the waves in order, each holding its own names sorted alphabetically. Return an empty list when some service can never be deployed, which covers a service depending on itself and any ring of services waiting on each other. An empty fleet returns an empty list too. A repeated entry means nothing extra.

Examples

deploy_waves(services: list[str], edges: list[str]) -> list[list[str]]
Example 1
Inputdeploy_waves(["api", "db", "web", "cache"], ["db>api", "api>web", "cache>web"])
Output[["cache", "db"], ["api"], ["web"]]
Example 2
Inputdeploy_waves(["s1", "s2", "s3"], ["s1>s2", "s1>s3", "s2>s3"])
Output[["s1"], ["s2"], ["s3"]]
Example 3
Inputdeploy_waves(["a", "b", "c"], ["a>b", "b>c", "c>a"])
Output[]