Harbor Container Shuffle Plan
The harbor's night crew rearranges shipping containers so that morning cranes can load vessels without delays. Every container is tagged with a numeric manifest ID, and the yard managers rely on a short list of written instructions. Each instruction selects a contiguous segment of the yard and restores that slice to ascending order, leaving the rest of the yard untouched. After all instructions finish, the operations team records the container order so they can reconcile which bays are already tidy and which still require manual work.
You will receive an initial list containers representing the row from left to right, plus a list plans where each entry is [start, end]. For each plan, sort containers[start..end] (inclusive) in ascending order while keeping elements outside the slice unchanged. Apply instructions sequentially; every index pair falls within the current array bounds and start <= end. When a slice is already sorted, leave it as-is. After processing all plans, return the updated array.
This simulator does not attempt to optimize runtime or compress steps; its goal is to mirror the crew's written checklist exactly.
Example 1:
Input: containers = [7,3,5,2,9], plans = [[0,2],[1,4]]
Output: [3,2,5,7,9]
Explanation: 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].
Example 2:
Input: containers = [4,1,6,3], plans = [[0,3],[0,1]]
Output: [1,3,4,6]
Explanation: Sorting the entire row yields [1,3,4,6]; the second command keeps the first two elements in order.
Example 3:
Input: containers = [5,8,2], plans = []
Output: [5,8,2]
Explanation: With no shuffle plans, the yard remains unchanged.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
