A platform runs serviceCount microservices and infrastructure components, labeled from 0 to serviceCount - 1. Find an order to start all components while respecting their dependencies.
List<Integer> findDeploymentOrder(int serviceCount, List<String> dependencies)
serviceCount: total number of components.dependencies: each string "A,B" means component B must be running before component A can start. Repeated pairs have the same effect as a single pair.1 ≤ serviceCount ≤ 100,0000 ≤ dependencies.size() ≤ 200,0000 ≤ A, B < serviceCountfindDeploymentOrder(serviceCount = 5, dependencies = List.of("0,2", "1,2", "3,0", "3,1"))
Output: [2, 0, 1, 3, 4]
Components 2 and 4 are initially ready. Starting 2 makes 0 and 1 ready. Always selecting the smallest ready ID gives the displayed order.
findDeploymentOrder(serviceCount = 4, dependencies = List.of("0,1", "1,0", "3,2"))
Output: []
Components 0 and 1 depend on each other, so starting every component is impossible.
findDeploymentOrder(serviceCount = 3, dependencies = List.of())
Output: [0, 1, 2]
With no dependencies, components start in increasing ID order.