Problem 52 of 75

Total Cost to Hire K Workers

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

costs[i] is the cost of hiring the i-th worker. Run k hiring sessions: in each, consider the first `candidates` workers and the last `candidates` workers still available, and hire the one with the lowest cost (lowest index on ties). Return the total cost to hire k workers.

(costs=[17,12,10,2,7,2,11,20,8], k=3, candidates=4) → 11

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Total Cost to Hire K Workers, explainedcodestorywithMIK