FastPrepFastPrep
Problem Brief

Get Most Hydrated Team

OA

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:

    1. 1. int[] cansConsumed: an array of integers representing the cans consumed by each employee
    2. 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

    Input
    cansConsumed = [70, 78, 53, 65, 100, 80, 92, 85, 43], manager = [8, 4, 3, -1, 3, 8, 4, 4, 3]
    Output
    85
    Explanation
    Example 1 illustration
    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.
    public int getMostHydratedTeam(int[] cansConsumed, int[] manager) {
      // write your code here
    }
    
    Input

    cansConsumed

    [70, 78, 53, 65, 100, 80, 92, 85, 43]

    manager

    [8, 4, 3, -1, 3, 8, 4, 4, 3]

    Output

    85

    Sign in to submit your solution.