Harbor Container Shuffle Plan
The harbor’s night crew rearranges shipping containers based on Shuffle Plans. Each plan specifies a range [start, end] in the yard that must be sorted into ascending order. Your mission in Harbor Container Shuffle Plan is to return the final container order after all plans have been executed sequentially.
The "secret sauce" here is In-Place Segment Sorting. You're given the initial list of containers and a sequence of plans. For each plan, you sort the containers within that specific range (inclusive) while leaving everything else in its current spot. Plans must be applied one by one, mirroring the crew’s written checklist. This simulation allows the operations team to confirm bays are tidy before the morning cranes arrive. It’s a great way to practice array slicing and sequence management under real-world constraints!
If sorting is part of the strategy, do it intentionally as a preprocessing step to simplify downstream logic such as merging, ordering, or comparison. After sorting, keep output semantics precise: preserve expected structure, avoid dropping valid entries, and ensure tied cases still follow deterministic order rules.
Examples
With no shuffle plans, the yard remains unchanged.
First sort the prefix [7,3,5] -> [3,5,7], producing [3,5,7,2,9]; next sort indices 1-4 to get [3,2,5,7,9].
Sorting the entire row yields [1,3,4,6]; the second command keeps the first two elements in order.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int[] harbor_container_shuffle_plan(int[] containers, int[][] plans) {
for (int[] plan : plans) {
Arrays.sort(containers, plan[0], plan[1] + 1);
}
return containers;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
