Schedule Delivery Jobs to Maximize Profit Before Deadlines
Last updated: November 29, 2026
Quick Overview
Each delivery job takes one time slot, has a deadline slot by which it must be completed, and earns a profit. With one driver who does one job per slot, choose jobs to maximize total profit.
Walmart Labs
November 29, 20260
0
0 solved
Each delivery job takes one time slot, has a deadline slot by which it must be completed, and earns a profit. With one driver who does one job per slot, choose jobs to maximize total profit.
Framed around last-mile delivery for Walmart+, where a driver's shift has a fixed number of slots and orders carry different value and promised windows. The Walmart Labs onsite interviewer checks a correct greedy, ideally the heap version, and a convincing argument for why it is optimal.
What the Interviewer Expects
- Sort jobs by deadline
- Maintain a min-heap of chosen profits
- Evict the least profitable job when the heap exceeds the current deadline
- Justify optimality with an exchange argument
- Compare with the slot-filling greedy and its cost
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you output the actual slot each job runs in?
- What if jobs take different durations?
- How would you handle two drivers instead of one?
- What if a late delivery is allowed but incurs a penalty?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of (job_id, deadline, profit) with integer deadlines, meaning the job must occupy one of slots 1 to deadline. One job per slot. Output: maximum total profit and the sorted ids of a set o...
High-Level Design
Process jobs by increasing deadline and keep the chosen set in a min-heap keyed on profit. Adding a job is fine as long as the chosen count does not exceed the current deadline, because all chosen job...