Individual contributors: hints, no solution
Easy · Trees
In a binary reporting tree, an individual contributor is an employee with no direct reports. Each node of the tree holds the employee's employee number.
The tree is given in level order: the root first, then the children of each present node from left to right, with null standing for a missing child. Nodes below a missing child are not listed.
Return the employee numbers of all individual contributors as a list, ordered by position from left to right as the tree would be drawn: a contributor in the left part of the tree comes before one in the right part, whatever their depth. An empty tree gives an empty list.
Examples
- Input
- tree = [6, 3, 9, 1, null, 8, 12]
- Output
- [1, 8, 12]
- Note
- Employees 1, 8 and 12 have no direct reports; employee 3 has a report, so it is not listed.
- Input
- tree = [4, null, 5, null, 7]
- Output
- [7]
- Note
- The tree is a single chain, so only its last employee qualifies.
Constraints
- 0 <= number of employees <= 2000
- Employee numbers are integers from 1 to 100000 and may repeat
Hint 1: a nudge
Which employees can you recognise as leaves just by looking at their own two links, without checking anyone else?
Unlock the full hints and timed practice with a pass
The second and third hints and the timed, runner-checked practice are part of a pass.