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
k
employees or the lastk
employees 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_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):
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
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.
π₯π₯

input:
output: