Palantir Foundry pipelines may produce datasets that depend on other datasets. Given the dependency relationships among n pipeline stages, return an execution order that satisfies every dependency, or return an empty list if the dependencies contain a cycle.
For each pair [stage, prerequisite], prerequisite must execute before stage. Every stage is identified by an integer from 0 through n - 1. If multiple valid orders exist, return any one of them.
Implement find_pipeline_order(n, dependencies), where n is an integer and dependencies is a list of integer pairs. Return a list containing every stage exactly once in valid execution order, or [] when no valid order exists.
def find_pipeline_order(n, dependencies):