AirtableOA #2
Get Most Hydrated Team
Estimated MediumStatement and editorial — judging is being prepared
Topics (AI-labelled)Tree TraversalHashing
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 consumed
manager[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.
Function Description
Complete the function getMostHydratedTeam in the editor.
getMostHydratedTeam has the following parameters:
-
int[] cansConsumed: an array of integers representing the cans consumed by each employee
-
int[] manager: an array of integers representing each employee's direct manager Returns int: the highest hydration score of any team
Example 1
Input:
cansConsumed = [70, 78, 53, 65, 100, 80, 92, 85, 43]
manager = [8, 4, 3, -1, 3, 8, 4, 4, 3]
Output:
85
Explanation: 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.
Editorial
Loading solution…