Minimum Rounds to Inform an N-ary Tree
Updated
Problem statement
The array parent describes a tree in which a node may have any number of children. Node 0 is the root, parent[0] = -1, and each other entry gives that node's parent.
At time zero only the root knows a message. In each round, every node that already knew the message at the beginning of the round may send it to at most one of its children that does not yet know it. Different informed nodes may send simultaneously. A child informed during a round can first send in the next round.
You may choose each node's child order. Return the minimum number of rounds needed to inform every node.
Function
minimumBroadcastRounds(parent: int[]) → intExamples
Example 1
parent = [-1,0,0,0]return = 3The root has three children and can inform only one per round, so three rounds are necessary.
Example 2
parent = [-1,0,0,1,3]return = 3Inform node 1 first. In round two the root informs node 2 while node 1 informs node 3. Node 3 informs node 4 in round three.
Constraints
1 <= parent.length <= 20000.- The array describes one valid tree rooted at 0.
- A parent index need not be smaller than its child index.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Minimum Cameras to Monitor a Binary TreeOYO Rooms · PHONE SCREEN
- Binary Tree CamerasAmazon · OA · PHONE SCREEN
- Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
- Tree Path GCDNewton School · PHONE SCREEN
- Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
- File Encryption Tree OptimizationDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Lowest Common Manager for Employee GroupsGoogle · PHONE SCREENGoogle interview questions
- Stock Profit With One, Unlimited, or Two TradesAdobe · PHONE SCREENAdobe interview questions
- Maximum Path Sum Between Marked NodesDoorDash · PHONE SCREENDoorDash interview questions
- House Robber IIIOkta · PHONE SCREENOkta interview questions