Moving Cost by Volume and Category
Reported by candidates from Wayfair's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Wayfair reported this one in September 2026, and it looks too easy to be dangerous. That's the trap. Moving Cost by Volume and Category is a single pass over packages, multiply three dimensions, multiply by the category rate, add it up. No clever data structure. The only thing that bites is integer overflow, and the third example is there to catch exactly that. If you're taking this OA in the next day or two, read the types before you write a line. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one you can do cold.
The problem
You are estimating one move. Each row packages[i] = [category, length, width, height] describes one rectangular package. Category IDs are zero-based indices into categoryRates. categoryRates[c] is the cost charged for moving one cubic unit of category c. A package's volume is length × width × height, and its moving cost is volume × categoryRates[category]. Return the total moving cost of all packages. Use 64-bit arithmetic for every product and the accumulated total. Function calculateMovingCost(packages: int[][], categoryRates: int[]) → long Examples Example 1 packages = [[0,2,3,4],[1,1,2,5]] categoryRates = [3,5] return = 122 The package volumes are 24 and 10, so the total cost is 24 × 3 + 10 × 5 = 122. Example 2 packages = [[2,3,3,3],[0,10,1,1],[2,1,1,1]] categoryRates = [2,7,4] return = 132 Category 2 contributes 28 cubic units at rate 4 and category 0 contributes 10 at rate 2, for total cost 28 × 4 + 10 × 2 = 132. Example 3 packages = [[1,100,100,100],[1,100,100,100],[1,100,100,100],[1,100,100,100]] categoryRates = [1,1000] return = 4000000000 Each package has volume 1,000,000 and costs 1,000,000,000. Four packages cost 4,000,000,000, which requires 64-bit accumulation. Constraints 1 <= packages.length <= 10000. Every row in packages contains exactly four integers [category, length, width, height]. 1 <= categoryRates.length <= 100, and 0 <= category < categoryRates.length. 1 <= length, width, height <= 100. 1 <= categoryRates[c] <= 1000. The returned total fits in a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is plain array iteration with a running sum. For each row, pull category, length, width, height. Compute volume as length * width * height, multiply by categoryRates[category], add to the total. The pitfall is overflow. One package can hit 100*100*100 = 1,000,000 volume, times a rate of 1000 gives 1,000,000,000. That's under the 32-bit max, but a product like volume * rate done in int arithmetic in some languages, or a sum across 10000 packages, will overflow. Cast to long before the first multiplication, not after. In Java, write (long) length * width * height * rate. In C++, use long long. Python doesn't care. Also don't mix up the row order: category comes first, not last. If you freeze on the types during the live OA, StealthCoder is the hedge that catches the cast you forgot.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Moving Cost by Volume and Category 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Wayfair's OA.
Wayfair 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.
Moving Cost by Volume and Category FAQ
How hard is the Wayfair Moving Cost problem really?+
Easy. It's one loop with a multiplication and a sum. The difficulty is entirely in not overflowing. If you can iterate an array and read a function signature, you can solve it. Most failures come from using 32-bit ints, not from the logic.
What's the trick in Moving Cost by Volume and Category?+
Use 64-bit arithmetic from the first multiplication. Cast one operand to long before multiplying, not the result afterward. Example 3 totals 4,000,000,000, which exceeds the signed 32-bit limit, so an int accumulator gives a wrong answer.
Do I need a hash map for the categories?+
No. Categories are zero-based indices into categoryRates, so you look up the rate directly by index. It's O(1) per package. A hash map adds code and risk for no benefit.
What's the time and space complexity?+
Time is O(n) where n is the number of packages, up to 10000. Space is O(1) beyond the input, since you only keep one running long total. No sorting or preprocessing is needed.
How do I prepare for this in 48 hours?+
Don't grind for this specific problem. Practice writing a typed loop in your language and check where overflow happens. Test with example 3 by hand. Then spend the remaining time on harder patterns, since the rest of the OA likely won't be this gentle.