Description
Solutions
Team Formation
πŸ‘©β€πŸŽ“ NEW GRAD

Given a list of employees where each is assigned a numeric evaluation score, use the selection process below to find the sum of scores of selected employees.

  1. The employee with the highest score among the first k employees or the last k employees in the score list is selected.
  2. The selected employee is removed from the score list.
  3. The process continues to select the next employee until the team_size is achieved.

Note:

  • In case multiple employees have the same highest score, the employee with the lowest index is selected.
  • If there are fewer than k employees, the entire list is available for selection.

Function Description

Complete the function teamFormation in the editor.

teamFormation has the following parameter(s):

  1. score[n]: an array of scores for each employee
  2. team_size: the number of team members required
  3. k: the size of the array segments to select from

Example 1:

Input:  score = [10, 20, 10, 15, 5, 30, 20], team_size = 2, k = 3
Output: 50
Explanation:

For the first selection, choose from the first 3 elements: [10, 20, 10] or the last 3 elements: [5, 30, 20]. Score 30 is selected and removed from the list. This makes score = [10, 20, 10, 15, 5, 20].

For the second selection, choose from [10, 20, 10] or [15, 5, 20]. Score 20 is selected from the lowest index and removed from the list. This makes score = [10, 10, 15, 5, 20].

The sum of the selected employees' scores is 30 + 20 = 50.

Constraints:
    πŸ₯πŸ₯
Thumbnail 0
Testcase

Result
Case 1

input:

output: