Split Packages Across K Delivery Vans With Identical Total Weight

Last updated: November 29, 2026

Quick Overview

Given package weights and an integer k, decide whether the packages can be split into k groups whose total weights are all equal, every package used exactly once.

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

0

0

0 solved


Given package weights and an integer k, decide whether the packages can be split into k groups whose total weights are all equal, every package used exactly once.

An onsite backtracking question in Amazon's style, framed around balancing load across last-mile vans leaving a delivery station. The interviewer is watching your pruning: sorting heavy packages first, skipping symmetric empty vans, and early exits on impossible targets.

What the Interviewer Expects
  • Checks divisibility and the max weight against the target first
  • Sorts weights in descending order to fail fast
  • Fills buckets with backtracking and undoes on failure
  • Skips equivalent buckets (same current load) to cut symmetry
  • Mentions the bitmask DP alternative for n up to 16
Key Topics to Cover
backtracking
pruning
partition problems
bitmask DP
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
  • How does the bitmask DP work and what is its complexity?
  • How would you approximate this when n is 10,000 and exact balance is not required?
  • How would you return the actual assignment?
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

Up to 16 packages, positive integer weights, 1≤k≤n1 \le k \le n. Return True if a perfect split exists. Every van must receive at least one package (implied by equal positive totals)....

High-Level Design

The target load per van is total / k; if that is not an integer, or one package exceeds it, answer False immediately. Otherwise assign packages one at a time to vans that still have room, backtracki...


Submit Your Answer
Markdown supported