Minimum Cost to Hire K Workers

HardHeapheap

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

There are n workers; worker i has a quality quality[i] and a minimum wage expectation wage[i]. You must hire exactly k workers and pay each of them under two rules: - Within the hired group, pay is proportional to quality: every hired worker earns the same amount per unit of quality. - Every hired worker is paid at least their minimum wage expectation. Return the minimum total amount of money needed to hire such a group, as a floating-point number. Answers within 10^-6 of the exact value are accepted.

Examples

Input: quality = [10,20,5], wage = [70,50,30], k = 2
Output: 105.0
Hire workers 0 and 2 at 7 per unit of quality: 70 + 35 = 105.
Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3
Output: 30.666666666666668
Hire workers 0, 2, 3 at 4/3 per unit: 4 + 13.333... + 13.333... = 30.666...

Constraints

  • n == quality.length == wage.length
  • 1 <= k <= n <= 10^4
  • 1 <= quality[i], wage[i] <= 10^4

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More heap problems