Problem
You get an integer array costs, where costs[i] is the cost to hire worker i. You also get two integers k and candidates. You hire exactly k workers in k rounds, one worker in each round.
In each round, examine only two groups of workers that are not hired yet. The first group is the first candidates of these workers. The second group is the last candidates of these workers. If the two groups overlap, examine all workers that are not hired yet.
From these workers, hire the worker with the lowest cost. If two workers have the same lowest cost, hire the worker with the smaller index. You can hire each worker only one time.
Return the total cost to hire the k workers.
Example 1
- Input:
- costs = [5,2,8,1,9,3,7], k = 3, candidates = 2
- Output:
- 10
- Explanation:
- Round 1 compares
[5, 2]and[3, 7]and hires the worker with cost 2. Round 2 compares[5, 8]and[3, 7]and hires cost 3. Round 3 hires cost 5.
Example 2
- Input:
- costs = [4,4,4,4], k = 2, candidates = 1
- Output:
- 8
- Explanation:
- In round 1, workers 0 and 3 have the same cost. Worker 0 has the smaller index, so you hire worker 0.
Example 3
- Input:
- costs = [6,1,6], k = 3, candidates = 5
- Output:
- 13
- Explanation:
- The groups overlap, so each round examines all workers. You hire all three workers.
Constraints
- 1 <= costs.length <= 10^5
- 1 <= costs[i] <= 10^5
- 1 <= k, candidates <= costs.length
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Minimum Cost to Hire K Workers
Coding · Array · Greedy · Heap (Priority Queue)
- Calculate Total Shipping Cost for an Order
Coding
- Maximize Total Cost of Alternating Subarrays
Coding
- Minimum Total Cost to Make Arrays Unequal
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 2462. Total Cost to Hire K Workers
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source