Code Logo

Harbor Container Shuffle Plan

Published at05 Jan 2026
Easy 31 views
Like14

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

Example 1
Input
containers = [4,1,2,3]
Output
[1,2,3,4]
Explanation

The full array is sorted from smallest to largest.

Example 2
Input
containers = [10,5,20,15]
Output
[5,10,15,20]
Explanation

Every value stays in the array, but the final order becomes ascending.

Example 3
Input
containers = [2,1]
Output
[1,2]
Explanation

Even a short array follows the same numeric sorting rule.

Algorithm Flow

Recommendation Algorithm Flow for Harbor Container Shuffle Plan

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

java
class Solution {
    public int[] harbor_container_shuffle_plan(int[] containers) {
        java.util.Arrays.sort(containers);
        return containers;
    }
}