Code RoomRelease train waves
EasyPrep Room Coding #4797

Release train waves

CodingAlgorithms & data structuresEntry–Mid~16 min

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.

Implement
deploy_waves(services: list[str], edges: list[str]) → list[list[str]]
Examples
in[["api","db","web","cache"],["db>api","api>web","cache>web"]]out[["cache","db"],["api"],["web"]]
in[["s1","s2","s3"],["s1>s2","s1>s3","s2>s3"]]out[["s1"],["s2"],["s3"]]
in[["a","b","c"],["a>b","b>c","c>a"]]out[]
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.

0:00 of about 16 min
InputExpectedGot
[["api","db","web","cache"],["db>api","api>web","cache>web"]][["cache","db"],["api"],["web"]]not run yetsample
[["s1","s2","s3"],["s1>s2","s1>s3","s2>s3"]][["s1"],["s2"],["s3"]]not run yetsample
[["a","b","c"],["a>b","b>c","c>a"]][]not run yetsample