Warehouse Crate Ordering
Distribution warehouse workers use a simulation tool to verify crate movement commands. Commands follow the format [source, destination, count]: remove count crates from the top of the source stack as a bundle and place them onto the destination stack without reversing their internal order. In Warehouse Crate Ordering, your mission is to report the final configuration of all stacks.
The "secret sauce" here is Bundle Slicing. For each move, you capture the top "slice" of the source stack and append it to the end of the destination stack in one motion. If a command asks for more crates than a stack currently holds, simply move all available crates. Be careful to preserve the "bottom-to-top" order of the labels in your lists. This ensures the delivery truck receives its cargo in the exact jumble the supervisor intended! Mastering this stack-based simulation is a great way to handle real-world inventory logic and multi-stage data transformations with professional precision.
Keep the algorithm focused on one clear invariant and update path so correctness is easy to verify from left to right. This reduces accidental branching errors and helps ensure the final output stays consistent with the problem contract across random and adversarial test shapes.
Examples
No commands means the stacks remain unchanged.
Command asks for three crates but stack 1 has only two, so both move onto stack 0.
Move two crates from stack 2 onto stack 0 (E,F), then move one crate from stack 0 onto stack 1 (now D on top of C).
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int[] sort_crates(int[] nums) {
int[] res = nums.clone(); Arrays.sort(res); return res;
}
}Related Stack Problems
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
