You are given an array of catalog numbers and need to return them in ascending order.
Nothing is removed along the way. Negative values stay, duplicate values stay, and if the list is empty the answer is just an empty list. The only change is the arrangement.
For example, nums = [6,-1,6,2] becomes [-1,2,6,6]. Both 6s are still there, just moved into the correct position. If nums = [3,1,4,1], the result is [1,1,3,4].
So the task is simply to line up the catalog values from smallest to largest.
Example Input & Output
Negative placeholders and repeats remain visible in ascending order.
A single sample remains unchanged because it is already in order.
Matching labels appear together after sorting while the smallest value leads the list.
Algorithm Flow

Solution Approach
This is a plain sorting problem. Any correct ascending sort works.
You can make a copy of the array and sort it numerically, or sort the array in place if that is allowed. The important detail is to compare numbers by value, not as strings.
Because duplicates and negative values are part of the input, the sort should keep every element exactly once and only change the order.
A comparison sort runs in O(n log n) time. Extra space depends on the language and sorting method you use.
Best Answers
import java.util.*;
class Solution {
public int[] catalog_shelf_lineup(int[] nums) {
int[] result = nums.clone();
Arrays.sort(result);
return result;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
