Skip to content

#2462 - Total Cost to Hire K Workers

MediumHeap / Priority Queue
Open on LeetCode

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.

InputOutput
costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 411
costs = [1,2,4,1], k = 3, candidates = 34

Released under the MIT License.