Frontend School

Identify High-Performing Teams

DSA
medium

Identify High-Performing Teams

Medium
Sorting
Searching
Data Structures
Arrays

Overview

In large organizations, identifying and recognizing high-performing teams is crucial for fostering a culture of excellence and strategic resource allocation. This problem simulates a scenario where you need to analyze employee performance data to pinpoint teams that consistently exceed expectations based on both individual contributions and collective performance.

What you need to do / Task

You are given a list of employee records, each containing an employee's ID, their team ID, and their individual performance score. Your task is to implement a function that identifies all unique team IDs corresponding to "high-performing" teams. A team is considered high-performing if it satisfies two specific criteria:

  1. Individual Contribution Threshold: The team must have at least minQualifiedMembers employees whose individual performance_score is greater than or equal to minIndividualScoreThreshold.
  2. Collective Performance Threshold: The team's overall average performance_score (sum of all members' scores divided by the total number of members) must be greater than or equal to minTeamAvgScoreThreshold.

The function should return a list of these unique high-performing teamIds, sorted alphabetically.

Input & output

Input:

  • employees: An array of objects, where each object represents an employee and has the following structure:
    • id: number (A unique identifier for the employee)
    • teamId: string (The identifier for the team the employee belongs to)
    • performanceScore: number (The employee's individual performance score, non-negative integer)
  • minIndividualScoreThreshold: number (The minimum score an individual employee must achieve to be considered 'qualified' for the first criterion, non-negative integer)
  • minQualifiedMembers: number (The minimum number of 'qualified' members a team must have to meet the first criterion, non-negative integer)
  • minTeamAvgScoreThreshold: number (The minimum average performance score a team must achieve to meet the second criterion, non-negative integer)

Output:

  • string[]: A list of unique teamIds that are identified as high-performing, sorted alphabetically.

Clarifications

  • An empty employees array should result in an empty list of high-performing teams.
  • performanceScore values are guaranteed to be non-negative integers.
  • minIndividualScoreThreshold, minQualifiedMembers, and minTeamAvgScoreThreshold are non-negative integers.
  • If no teams meet the criteria, an empty array should be returned.
  • Team IDs are strings and can contain alphanumeric characters.

Examples

1

Example 1

Input:

employees = [{id:1, teamId:'A', performanceScore:80}, {id:2, teamId:'B', performanceScore:90}, {id:3, teamId:'A', performanceScore:75}, {id:4, teamId:'C', performanceScore:60}, {id:5, teamId:'B', performanceScore:85}, {id:6, teamId:'A', performanceScore:95}, {id:7, teamId:'C', performanceScore:70}], minIndividualScoreThreshold = 80, minQualifiedMembers = 2, minTeamAvgScoreThreshold = 85

Output:

["B"]

Note:

Team A: Scores [80, 75, 95]. Qualified members (score >= 80): 2 (for 80, 95). Meets minQualifiedMembers (2 >= 2). Average score: (80+75+95)/3 = 83.33. Does NOT meet minTeamAvgScoreThreshold (83.33 < 85). Team B: Scores [90, 85]. Qualified members (score >= 80): 2 (for 90, 85). Meets minQualifiedMembers (2 >= 2). Average score: (90+85)/2 = 87.5. Meets minTeamAvgScoreThreshold (87.5 >= 85). Team B is high-performing. Team C: Scores [60, 70]. Qualified members (score >= 80): 0. Does NOT meet minQualifiedMembers (0 < 2).

2

Example 2

Input:

employees = [{id:1, teamId:'X', performanceScore:90}, {id:2, teamId:'Y', performanceScore:88}, {id:3, teamId:'X', performanceScore:92}, {id:4, teamId:'Y', performanceScore:85}, {id:5, teamId:'Z', performanceScore:95}, {id:6, teamId:'Z', performanceScore:90}], minIndividualScoreThreshold = 85, minQualifiedMembers = 2, minTeamAvgScoreThreshold = 87

Output:

["X", "Y", "Z"]

Note:

Team X: Scores [90, 92]. Qualified members (score >= 85): 2. Average: (90+92)/2 = 91. Both criteria met. Team Y: Scores [88, 85]. Qualified members (score >= 85): 2. Average: (88+85)/2 = 86.5. Both criteria met. Team Z: Scores [95, 90]. Qualified members (score >= 85): 2. Average: (95+90)/2 = 92.5. Both criteria met. All teams are high-performing. Output is sorted alphabetically.

3

Example 3

Input:

employees = [{id:1, teamId:'Alpha', performanceScore:70}, {id:2, teamId:'Beta', performanceScore:75}, {id:3, teamId:'Alpha', performanceScore:60}, {id:4, teamId:'Beta', performanceScore:65}], minIndividualScoreThreshold = 80, minQualifiedMembers = 1, minTeamAvgScoreThreshold = 70

Output:

[]

Note:

Team Alpha: Scores [70, 60]. Qualified members (score >= 80): 0. Does not meet minQualifiedMembers. Team Beta: Scores [75, 65]. Qualified members (score >= 80): 0. Does not meet minQualifiedMembers. No teams are high-performing.

Constraints

Constraints & assumptions

  • 1 <= employees.length <= 10^5
  • 1 <= employee.id <= 10^9 (unique)
  • 1 <= employee.teamId.length <= 10
  • 0 <= employee.performanceScore <= 100
  • 0 <= minIndividualScoreThreshold <= 100
  • 0 <= minQualifiedMembers <= employees.length
  • 0 <= minTeamAvgScoreThreshold <= 100
  • The number of unique teams M will be between 1 and employees.length.

What interviewers evaluate

  • Algorithmic Efficiency: Ability to design an algorithm that processes the data efficiently, especially considering large datasets.
  • Correctness: The solution must correctly apply both criteria for identifying high-performing teams and handle edge cases gracefully.
  • Data Structure Usage: Appropriate selection and use of data structures (e.g., for grouping, sorting, and aggregation).
  • Code Quality: Readability, organization, and maintainability of the code.

Loading editor...