Practice Count Visited Nodes in a Directed Graph
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
The directed graph has one outgoing edge from each node i to edges[i]. Starting separately from each node, repeatedly follow outgoing edges until the next node has already been visited in that walk. Return an array containing the number of distinct visited nodes for each start, including the starting node.
Source: Count Visited Nodes in a Directed Graph on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
edges = [1,2,0,0]
[3,3,3,4]
# Example 2
edges = [1,2,3,4,0]
[5,5,5,5,5]
Constraints
Related LeetCode Problems
Practice more problems similar to Count Visited Nodes in a Directed Graph.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.