Total Cost to Hire K Workers
Medium · Heap & Priority Queue · about 25 minutes
Asked at Amazon, Google, Microsoft.
costs[i] is the cost of hiring worker i. You run k hiring sessions, hiring one worker per session: pick the cheapest worker among the first candidates workers and the last candidates workers still available (ties go to the smaller index). If fewer than candidates workers remain on a side, choose among all of them. Return the total cost of the k hires.