Reported March 2026
Amazondynamic programming

The Best Way To Pack

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's "The Best Way To Pack" showed up in March 2026 OAs, and it's a deceptively simple-sounding problem that trips up candidates who don't see the optimization angle. You get a set of items with weights and values, constraints on packing capacity, and you need to maximize what you ship. This is a classic knapsack variant, and if you blank on the DP recurrence during the live OA, StealthCoder will have your back with the exact state transitions you need.

Pattern and pitfall

The trick here is recognizing that 'best' means maximum value within a weight limit, not just greedy item selection. Most candidates try to sort by value-to-weight ratio and pick greedily. That fails on test cases where a heavier, higher-value item outweighs two lighter, low-value items. The real solution is dynamic programming: build a table where dp[i][w] = max value using first i items with weight limit w. Fill it bottom-up, and for each item decide: include it or skip it. The recurrence is dp[i][w] = max(dp[i-1][w], dp[i-1][w-weight[i]] + value[i]). Time is O(n*W) where W is capacity. If you freeze on the live OA, StealthCoder reads the constraints and gives you the exact DP skeleton you need to code it fast.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill The Best Way To Pack cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as partition equal subset sum. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

The Best Way To Pack FAQ

Is this the 0/1 knapsack problem?+

Yes. You pack each item once or not at all. You're not buying unlimited quantities. Amazon uses this to model real warehouse bin-packing scenarios. The DP approach is the standard solution.

What if the capacity is huge, like 10^9?+

Then 0/1 knapsack DP fails (you can't allocate a 10^9 table). You'd need a different approach, possibly branch-and-bound or approximation. But most Amazon OAs keep W small enough for DP. Check your constraints first.

Do I need to output which items to pack, or just the max value?+

The problem usually asks for max value. If it asks for the items themselves, backtrack through the DP table from dp[n][W] to recover which items were chosen.

How much time should I spend on this in the OA?+

If you recognize the knapsack pattern, code it in 15-20 minutes. Don't overthink greedy heuristics. DP is the safe, correct path. Space optimization (rolling a 1D array) is a bonus, not required.

Is there a greedy solution that works?+

No. Greedy by value, greedy by weight, greedy by ratio all fail on carefully crafted test cases. DP is the only reliable method for the general 0/1 knapsack problem.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it