Team Formation
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.
- The employee with the highest score among the first
kemployees or the lastkemployees in the score list is selected. - The selected employee is removed from the score list.
- The process continues to select the next employee until the
team_sizeis achieved.
Note:
- In case multiple employees have the same highest score, the employee with the lowest index is selected.
- If there are fewer than
kemployees, the entire list is available for selection.
Complete the function teamFormation in the editor.
teamFormation has the following parameter(s):
score[n]: an array of scores for each employeeteam_size: the number of team members requiredk: the size of the array segments to select from
1Example 1
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
Limits and guarantees your solution can rely on.
🥝🥝