New
The Learning module is now live
See what's new
×
Question Bank
Learning
NEW
Pricing
Blog
Forum
HOT
JobRadar
Description
Solution
Discussion
Submissions
Ask AI
Question Bank
Coding Question
AI Insights
Quick Summary
Given a list of parent-child relationships forming a forest, determine which tree contains the maximum number of nodes.
Identify tree roots by finding nodes that appear as parents but never as children in the input.
Return the root ID of the largest tree, using the smallest ID as a tie-breaker.
What This Tests
Constructing and traversing graphs or forests using adjacency lists.
Implementing tree traversal algorithms like DFS or BFS to count nodes.
Using hash maps or sets to efficiently track node roles and relationships.
Handling disconnected components within a single dataset.
Common Patterns
Graph Traversal
DFS/BFS
Hashing
Collapse
Hint 1
Hint 2
What Interviewers May Ask Next
Accepted
56
/134
Acceptance Rate
41.8%
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
Qwen
Qwen3.6-Flash
0/2000
Auto
Debug
Run
Submit
Test Cases
Input
relations =
Output
Expected