Get Most Hydrated Team
Problem statement
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 employeei's cans consumedmanager[i]represents employeei's direct manager (-1indicates 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.
Function
getMostHydratedTeam(cansConsumed: int[], manager: int[]) → int
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
Examples
Example 1
cansConsumed = [70, 78, 53, 65, 100, 80, 92, 85, 43]manager = [8, 4, 3, -1, 3, 8, 4, 4, 3]return = 85
The team under employee 4 has three employees. Their hydration score is (78 + 85 + 92)/3 = 255/3 = 85. This is the highest hydration score of any team.