Topological Sort (Resume/Project-based DSA Round)
viaGlassdoor
Problem: Produce a valid topological ordering of the nodes of a directed acyclic graph (DAG), asked as the coding portion of a technical round following project/resume discussion.
Approach: Kahn's algorithm -- repeatedly remove nodes with in-degree 0, append them to the ordering, and decrement neighbors' in-degrees; if fewer than all nodes are processed, the graph has a cycle. Alternatively, DFS-based ordering: perform a post-order DFS, push each node once fully explored onto a stack, then reverse the stack for the topological order. O(V+E) time.
asked …