Search
⌘K

Leetcode 2192. All Ancestors of a Node in a Directed Acyclic Graph

Given a DAG with n nodes and directed edges, compute for each node the sorted list of all nodes that can reach it (its ancestors). This is essentially computing the transitive closure/reachability for every node, leveraging the DAG/topological ordering to do it efficiently within the n ≤ 1000 constraint.

Asked at:

Amazon

Amazon


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Mid October, 2024

Amazon

Amazon

Mid-level

Find the number of ancestors of a person and list ancestors from oldest to newest

Comments

Your account is free and you can post anonymously if you choose.