#2462 - Total Cost to Hire K Workers
You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the i-th worker. You are also given two integers k and candidates. In each hiring round, choose the worker with the lowest cost from either the first candidates workers or the last candidates workers (remove them from the pool). Hire exactly k workers. Return the total cost.
| Input | Output |
|---|---|
costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4 | 11 |
costs = [1,2,4,1], k = 3, candidates = 3 | 4 |