Get Most Hydrated Team
The engineering organization is having an offsite, and everyone has been tasked with coming up with a piece of AIrtable trivia they can share with the team. You've decided to find out which engineering team is the most hydrated, based on the average cans of sparkling water consumed by all employees on that team in the last year.
There are n employees, numbered from 0 to n-1. You are given two integer arrays cansConsumed and manager of length n, where:
cansConsumed[i] represents employee i's cans consumedmanager[i] represents employee i's direct manager (-1 indicates no manager)A "team" consists of all employees who report to a common manager (directly or indirectly through other managers). The common manager is not part of the team.
The hydration score of a team is the average cans consumed of all employees on that team.
Return the hydration score of the team with the highest hydration score. Only consider teams with 2 or more employees.
Complete the function getMostHydratedTeam in the editor.
getMostHydratedTeam has the following parameters:
- 1.
int[] cansConsumed: an array of integers representing the cans consumed by each employee - 2.
int[] manager: an array of integers representing each employee's direct manager
Returns
int: the highest hydration score of any team
🧡 Manyyy thanks to the amazing friend who generously shared the source!
1Example 1
