Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
Backend Engineer Senior programming

Given a directed acyclic graph represented as an adjacency list and a starting node, return a list of all nodes reachable from the starting node following the edges of the graph.


Function Signature: def reachable_nodes(graph: List[List[int]], start: int) -> List[int]:
Constraints:
  • The number of nodes will be between 1 and 10^4.

  • Each node is labeled with integers from 0 to n-1, where n is the number of nodes.


Example 1:
Input: graph = [[1], [2], []], start = 0
Output: [0, 1, 2]
Example 2:
Input: graph = [[2], [2], []], start = 1
Output: [1, 2]
Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free
Link copied to clipboard