You are given an integer array costs, where costs[i] represents the hiring cost of worker i.
You are also given two integers k and candidates. You want to hire exactly k workers according to the following rules:
In each of the k hiring sessions, you choose the worker with the minimum cost from either the first candidates available workers or the last candidates available workers. If there is a tie with the same minimum cost, choose the worker with the smallest index. If the number of remaining workers is strictly less than candidates, choose the worker with the minimum cost among all remaining workers, breaking ties by the smallest index.
Each chosen worker is removed from the array and cannot be selected in subsequent sessions.
Return the total cost required to hire k workers.
Constraints:
costs.length
costs[i]
k, candidates costs.length
You are given an integer array costs, where costs[i] represents the hiring cost of worker i.
You are also given two integers k and candidates. You want to hire exactly k workers according to the following rules:
In each of the k hiring sessions, you choose the worker with the minimum cost from either the first candidates available workers or the last candidates available workers. If there is a tie with the same minimum cost, choose the worker with the smallest index. If the number of remaining workers is strictly less than candidates, choose the worker with the minimum cost among all remaining workers, breaking ties by the smallest index.
Each chosen worker is removed from the array and cannot be selected in subsequent sessions.
Return the total cost required to hire k workers.
Constraints:
costs.length
costs[i]
k, candidates costs.length