Harbor Container Shuffle Plan
In this task, 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.
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.
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. Always use a numeric comparator: arr.sort(function(a,b){return a-b;}).
In Python you can use the built-in sorted() function. In Java, Arrays.sort() works with integers natively. In PHP, sort() with the SORT_NUMERIC flag is sufficient. In Rust, nums.sort() on a Vec<i32> sorts in place.
Best Answers
class Solution {
public int[] harbor_container_shuffle_plan(int[] containers) {
java.util.Arrays.sort(containers);
return containers;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
