Warehouse Crate Ordering
A distribution warehouse organizes crates into labeled stacks so each delivery truck receives its cargo in order. The supervisor provides workers with a list of commands that repeatedly select a stack, remove a fixed number of crates from its top, and place those crates onto another stack without changing their internal order. To verify the instructions, the supervisor wants a simple simulation that reports the crate labels from top to bottom after all commands execute.
You will receive an array stacks where each entry is a list of crate labels arranged from bottom to top, and a list moves describing the commands. Each command is formatted as [source, destination, count]. First, remove count crates from the top of stacks[source] as a bundle, preserving their order. Then append that bundle to the top of stacks[destination] without reversing it. If a command requests more crates than a stack currently holds, remove all available crates instead. Commands never reference invalid stack indices.
Return the final configuration of stacks as a list of lists, each still ordered from bottom to top. Avoid mutating the input arrays in place unless you copy them. Focus on matching the written instructions; efficiency is secondary for this audit tool.
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.
