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.
Example 1:
Input: stacks = [["A","B"],["C"],["D","E","F"]], moves = [[2,0,2],[0,1,1]]
Output: [["A","B","E","F"],["C","D"],[]]
Explanation: 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).
Example 2:
Input: stacks = [["X"],["Y","Z"]], moves = [[1,0,3]]
Output: [["X","Y","Z"],[]]
Explanation: Command asks for three crates but stack 1 has only two, so both move onto stack 0.
Example 3:
Input: stacks = [["M","N"],["P"]], moves = []
Output: [["M","N"],["P"]]
Explanation: No commands means the stacks remain unchanged.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
