bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1557. Minimum Number of Vertices to Reach All Nodes

1557. Minimum Number of Vertices to Reach All Nodes

Leetcode Solutions

Finding Minimum Set of Vertices for Reachability in a DAG

  1. Initialize an array isIncomingEdgeExists of size n with false values.
  2. Iterate over the edges array. For each edge [from, to], set isIncomingEdgeExists[to] to true.
  3. Initialize an empty list requiredNodes.
  4. Iterate over the isIncomingEdgeExists array. For each index i where isIncomingEdgeExists[i] is false, add i to requiredNodes.
  5. Return the list requiredNodes.
UML Thumbnail

Depth-First Search to Find Minimum Set of Source Vertices

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...