Maximum Invitations on an N-ary Tree
Updated
Problem statement
You are given a tree in which each node may have any number of children. Its nodes are 0 through n - 1, and node 0 is the root. The array parent has parent[0] = -1; every other entry names that node's parent.
Choose as many nodes as possible to receive invitations. Two nodes connected by a tree edge cannot both receive an invitation. Return the maximum number of invited nodes. Every node contributes one invitation; there are no node weights.
Function
maximumInvitations(parent: int[]) → intExamples
Example 1
parent = [-1,0,0,1,1]return = 3Inviting nodes 2, 3, and 4 is valid. No selection can contain more than three nodes.
Example 2
parent = [-1,0,0,0]return = 3Invite all three leaves and leave the root uninvited.
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
- House Robber IIIOkta · PHONE SCREENOkta interview questions
- House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- House Robber IIIVisa · PHONE SCREENVisa interview questions
- Normalize Loan Merchants to Root BusinessesAffirm · PHONE SCREENAffirm interview questions
- Minimum Root-to-Leaf Cut CostGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Predicate Expression Tree EvaluatorMongoDB · PHONE SCREENMongoDB interview questions
- Maximum Nonadjacent Sum in a General TreeZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
- Minimum-Cost Root-to-Leaf Path in an N-ary TreeBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Every Full Binary Tree With n NodesAdobe · PHONE SCREENAdobe interview questions
- Tree Path GCDNewton School · PHONE SCREEN