Hire K Delivery Contractors at Minimum Total Pay Under Proportional Rates

Last updated: November 29, 2026

Quick Overview

Contractor i has a quality score q[i] and a minimum acceptable wage w[i]. Hire exactly k contractors so that each is paid in proportion to quality within the group and at least their minimum. Return the least total pay.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Contractor i has a quality score q[i] and a minimum acceptable wage w[i]. Hire exactly k contractors so that each is paid in proportion to quality within the group and at least their minimum. Return the least total pay.

An Amazon onsite hard question, framed around Delivery Service Partner staffing, that tests greedy plus heap reasoning. The interviewer wants you to see that one hired contractor's wage-to-quality ratio sets the pay rate for the group, and to sweep that ratio with a max-heap of qualities.

What the Interviewer Expects
  • Derives that pay = rate * total quality with rate = max ratio in the group
  • Sorts contractors by w / q ascending
  • Keeps a max-heap of the k smallest qualities seen
  • Evaluates rate * sum_quality each time the heap has k entries
  • Runs in O(n log n)
Key Topics to Cover
greedy
heap
sorting by ratio
optimization
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Each contractor also has a region and at most m can come from one region.
  • Return which contractors to hire.
  • How does this change if pay must be an integer number of dollars?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: lists quality and min_wage of length n, and 1 <= k <= n. Output: minimum total pay (float) for a group of exactly k. Within the group, pay[i] / q[i] is the same for everyone, and pay[i] >= w[i]...

High-Level Design

If the group pays a common rate r per unit of quality, everyone needs r >= w[i] / q[i], so the cheapest r is the maximum ratio in the group, and total pay is r times the sum of qualities. Sort contrac...


Submit Your Answer
Markdown supported