BudiBadu Logo

Conveyor Batch Sequence

Sorting Easy 3 views
Like15

Technical Goal

Implement a function that takes an array of integers and returns a new array with the elements sorted in ascending order. The original array must remain unchanged.

Constraints

  • nums: An array of integers (can include negative numbers and duplicates).
  • Return a new sorted array; do not modify the original.
  • Empty input should return an empty array.

Example 1:

Input: nums = [12, 7, 7, 9]
Output: [7, 7, 9, 12]
Explanation: Duplicate weights remain while the list climbs from lightest to heaviest.

Example 2:

Input: nums = []
Output: []
Explanation: An empty feed results in an empty ordered list.

Example 3:

Input: nums = [-2, 5, -2, 3]
Output: [-2, -2, 3, 5]
Explanation: Negative markers and positive weights are preserved in ascending order.

Algorithm Flow

Recommendation Algorithm Flow for Conveyor Batch Sequence - Budibadu
Recommendation Algorithm Flow for Conveyor Batch Sequence - Budibadu

Best Answers

java
import java.util.*;

class Solution {
    public int[] conveyor_batch_sequence(int[] nums) {
        int[] result = nums.clone();
        Arrays.sort(result);
        return result;
    }
}