Deploy pipeline chain
A deploy pipeline is stored the way a linked list is stored in a flat table. Step i is named names[i], and next_step[i] holds the index of the step that runs immediately after step i, or -1 when step i is the last one. The two lists have the same length, and every entry of next_step is either -1 or a valid index, possibly the step's own index. A healthy pipeline is one single chain: exactly one step has nothing pointing at it, and following the chain from that step reaches every step exactly once. Return the step names in execution order. Return an empty list when the table is not one healthy chain, which covers two steps claiming the same successor, a count of starting steps other than one, and steps sitting in a loop the start never reaches.
pipeline_step_order(names: list[str], next_step: list[int]) → list[str][["build","test","ship"],[1,2,-1]]out["build","test","ship"][["build","test","ship"],[-1,0,1]]out["ship","test","build"][["a","b"],[1,0]]out[]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.
[["build","test","ship"],[1,2,-1]]["build","test","ship"]not run yetsample[["build","test","ship"],[-1,0,1]]["ship","test","build"]not run yetsample[["a","b"],[1,0]][]not run yetsample