Practice/Uber/Package Installation Order
CodingMust
You are building a software system with multiple modules that have dependencies on each other. Before a module can be built, all of its dependencies must be built first.
Given the total number of modules (numbered from 0 to modules - 1) and a list of dependency pairs, determine a valid order in which to build all modules. Each dependency pair [a, b] means that module a depends on module b, so module b must be built before module a.
If there is a circular dependency that makes it impossible to build all modules, return null (or None in Python).
b must appear before module a in the resultnullExample 1:
` Input: modules = 4, dependencies = [[1, 0], [2, 1], [3, 2]] Output: [0, 1, 2, 3] Explanation:
Example 2:
Input: modules = 3, dependencies = [[0, 1], [1, 2], [2, 0]] Output: null Explanation: There is a circular dependency cycle: 0 → 1 → 2 → 0 This makes it impossible to determine a valid build order.
Example 3:
` Input: modules = 5, dependencies = [[1, 0], [2, 0], [3, 1], [4, 2]] Output: [0, 1, 2, 3, 4] (or [0, 2, 1, 4, 3] or other valid orderings) Explanation: