I recently interviewed for Google. My first round of interview had this question. Which should I solve within 40 mins
You work in Human Resources of a large company, and during a recent review, you come to realize that some managers might seem underpaid.
To ensure fairness, you come up with an impartial rule:
A manager is underpaid if and only if their salary is less than the average
of the salaries of all their direct and indirect reports.
For example, consider the following:
A($100)
|
+-B($100) +- C($200)
| |
E(200) D($60)Here A is underpaid, since the average salary of their reports is (200+200) / 4 = 100.
Question: Given an organization tree, return the count of underpaid managers.
I solved it using DFS , Dry run failed some testcases. Interview result is not yet announced.