Topological Sort

Given vertexCount vertices numbered 0 through vertexCount-1 and directed edges [from, to] forming a directed acyclic graph, return any topological ordering.…

Given vertexCount vertices numbered 0 through vertexCount-1 and directed edges [from, to] forming a directed acyclic graph, return any topological ordering. The result must contain every declared vertex exactly once, and from must appear before to for every edge. Include isolated vertices. Multiple valid answers are accepted.

- 1 <= vertexCount <= 10000 - 0 <= edges.length <= 10000 - Every edge contains two integer vertex IDs in 0..vertexCount-1 - The directed graph is acyclic; duplicate edge occurrences are allowed - The preset visualizer uses DAGs with at most 24 vertices and 48 edge occurrences; larger valid inputs remain execution-only

Example 1: input vertexCount = 4, edges = [[0,2],[1,2]]; output [0,1,3,2]. Vertices 0 and 1 precede 2. Vertex 3 is isolated and may appear anywhere. [1,0,2,3] is also valid.

Example 2: input vertexCount = 3, edges = [[2,1],[1,0]]; output [2,1,0]. The dependencies force 2 before 1 and 1 before 0; numeric sorting is not a solution.

Category: Graphs. Topic: graph. Difficulty: Medium. Patterns: graph-traversal.