Harbor Container Shuffle Plan
In Harbor Container Shuffle Plan, the tested task is much simpler than the older story text suggests. You are given one array of integers and need to return those same numbers sorted from smallest to largest.
This means you are not applying several shuffle plans, sorting subranges, or simulating multiple operations. The real job is just a full ascending sort of the input array. Every number should still appear in the answer, including duplicates. Negative values and zero also follow normal numeric order, so they should appear before larger positive values when appropriate.
For example, containers = [4,1,2,3] should become [1,2,3,4]. Another example is containers = [10,5,20,15], which should become [5,10,15,20]. If the input is [2,1], the answer is [1,2]. If the input is empty, the result is an empty array.
So the actual task is to sort the full array numerically in ascending order and return the sorted list.
Example Input & Output
The full array is sorted from smallest to largest.
Every value stays in the array, but the final order becomes ascending.
Even a short array follows the same numeric sorting rule.
Algorithm Flow

Solution Approach
The cleanest way to solve this problem is to sort the array in ascending numeric order and return the result. Since the judge only checks whether the final array is sorted from smallest to largest, a direct numeric sort matches the requirement exactly.
The only detail that can trip you up is how the sort behaves in your language. In JavaScript, for example, calling sort() without a comparator can compare values as strings. That can produce incorrect results when the array contains multi-digit values, because text ordering is different from numeric ordering. A value like 10 could be placed before 2 if you are not careful. So even for an easy problem, it is worth stating the comparison rule explicitly.
A straightforward JavaScript version looks like this:
The copied array is optional, but it is useful if you want to avoid mutating the original input. The comparator a - b ensures that smaller values move earlier in the array and larger values move later. Equal values stay as separate entries, so duplicates are preserved automatically.
This handles all of the important edge cases without special branches. If the array is empty, sorting it still gives an empty array. If the array has one element, it is already sorted. If the array contains duplicates such as [5, 5, 1], both 5 values remain in the result. If it contains negative numbers like [-3, 0, 7], the numeric comparator correctly places the negative value first.
The time complexity is O(n log n), which is the standard cost of comparison sorting. The extra space depends on the language and on whether you sort in place or use a copied array like the example above.
So the full strategy is simple: take the container list, apply an ascending numeric sort with an explicit comparator, and return the sorted array with every original number still included.
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 Challenge.
