recently, one of my friend gave google interview and the question goes
Given a hierarchy of managers, as a tree, with every mode value is the salary of the manager, find out the number of managers underpaid.
How are they underpaid? if salary of manager is lesser than the average of its children nodes salary.
I understand the problem, just dont know how to optimally aproach it... any solutions please?