Find number of Employees Under every ManagerAn employee and his boss are mapped in a dictionary as a number of (employee, manager) pairs, as shown below. Create a function to return the total number of employees, not just their direct reports, that each manager in the hierarchy has. One boss may be presumed to be the only one to whom an employee directly reports. The root node/ceo is listed as reporting to himself in the aforementioned vocabulary. An output dictionary with the following words should be produced. There may be more ways to answer this, but I found it fascinating and thought I'd share: Utilizing memory (Dynamic programming) to determine the number of employees under a management in step 2.b saves us from having to repeat the process for for individual employee. In the code below, the recursive function populateResultUtil() makes use of memoization to prevent re-computation of the same results. Code in C++Output: result = {A=0, B=0, C=2, D=0, E=1, F=5} |
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week