Analyze Underpaid Managers in a Salary Tree
Updated
Problem statement
A company hierarchy is a rooted tree. parent[i] is the direct manager of employee i, or -1 for the root. salary[i] is the employee's positive integer salary.
For every manager with at least one direct or indirect report, compare the manager's salary with all direct and indirect reports:
- Count managers whose salary is strictly below the average of their reports' original salaries.
- Compute the minimum total integer salary increase needed so that no manager is below the average of all direct and indirect reports' final salaries. Salaries may only increase. Leaves remain unchanged.
- Count managers whose salary is strictly below the median of their descendants' original salaries. For an even descendant count, the median is the average of the two middle values.
Return these three results as [meanCount, minimumBudget, medianCount].
Function
analyzeManagerSalaries(parent: int[], salary: int[]) → long[]Examples
Example 1
parent = [-1,0,0]salary = [50,60,80]return = [1,20,1]The root's descendant mean and median are both 70, so it needs a raise from 50 to 70.
Example 2
parent = [-1,0,1,1]salary = [10,10,30,50]return = [2,60,2]Manager 1 rises from 10 to 40. The root's final descendants are then 40, 30, and 50, so the root also rises from 10 to 40. The total budget is 60.
Example 3
parent = [-1,0,0,1]salary = [100,80,60,40]return = [0,0,0]No manager is below either descendant statistic, and no raise is needed.
Constraints
1 <= parent.length = salary.length <= 200.- Exactly one entry of
parentis-1; all other entries form one rooted tree. 1 <= salary[i] <= 10^9.- The final budget fits a signed 64-bit integer.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Recursive Display SortFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Lowest Common Manager for Employee GroupsAmazon · PHONE SCREEN
- File Encryption Tree OptimizationDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Vertical Order Traversal of a Binary TreeBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Vertical Tree Traversal with Value TiesMeta · PHONE SCREENMeta interview questions
- Maximum Path Sum Between Marked NodesDoorDash · PHONE SCREENDoorDash interview questions
- House Robber IIIOkta · PHONE SCREENOkta interview questions
- House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- House Robber IIIVisa · PHONE SCREENVisa interview questions
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions