Zero or One Parent Groups in a Tree
Updated
Problem statement
Each row of pairs is [parent,child]. Return the represented nodes with no direct parents and the represented nodes with exactly one direct parent.
For this exercise, assume the unique relationships form one rooted tree when nonempty: they are connected, acyclic, and each non-root node has exactly one parent. Repeated copies of an edge have no effect. Only IDs appearing in a pair are represented; empty input represents an empty tree.
For this exercise, assume the result is exactly [roots,nodesWithOneParent], with each row sorted by increasing numeric ID. Empty input returns [[],[]].
Function
findTreeParentGroups(pairs: int[][]) → int[][]Examples
Example 1
pairs = [[8,2],[8,9],[2,5]]return = [[8],[2,5,9]]This rooted tree has root 8 and one-parent nodes 2,5,9.
Example 2
pairs = []return = [[],[]]The empty representation returns two empty groups; no separate isolated-node list is supplied.
Constraints
- For this exercise, assume
0 <= pairs.length <= 1000. - Each row contains two positive integer IDs, each at most
10^9. - After duplicate edges are ignored, nonempty input represents one rooted tree.
More Intuit interview questions
- VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
- Longest Uninterrupted Work BlockPHONE SCREEN · Seen Sep 2026
- VIP-Priority Fixed-Window Rate LimiterPHONE SCREEN · Seen Aug 2026
- Small Business Network: Degrees of SeparationPHONE SCREEN · Seen May 2026
- Longest Common SubstringPHONE SCREEN · Seen May 2021
- Lowest Common Ancestor in a Rooted TreePHONE SCREEN · Seen Feb 2020
- Number of IslandsONSITE INTERVIEW · Seen Nov 2026
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
Similar questions at other companies
- Mode of a Ternary Search TreeGoogle · PHONE SCREENGoogle interview questions
- Org Chart Report CountsPatreon · PHONE SCREENPatreon interview questions
- Tree Nodes with Zero or One ParentWayfair · PHONE SCREENWayfair interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Lowest Common Ancestor in an N-ary TreeAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
- Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions