Code Logo

Atrium Roster Sorted Signal

Published at05 Jan 2026
Easy 3 views
Like21

In Atrium Roster Sorted Signal, you are given an array of integers and asked to return the same values sorted from smallest to largest.

This problem is about ordering, not filtering. You should keep every number that appears in the input. If a value shows up more than once, it should also appear more than once in the output. Negative numbers matter too, so a value like -5 belongs before 0, and 0 belongs before any larger positive number.

For example, if the input is nums = [18,4,9,4], the correct output is [4,4,9,18]. The two 4 values are both preserved; they are just moved into their proper positions. If the input is nums = [0,-3,7], the correct output is [-3,0,7] because -3 is the smallest value in the array.

An empty array stays empty, and an array with one value stays the same. So the task is simply to arrange the entire list in ascending numeric order and return that sorted array.

Example Input & Output

Example 1
Input
nums = [18,4,9,4]
Output
[4,4,9,18]
Explanation

The numbers are returned in ascending order, and the duplicate 4 is kept.

Example 2
Input
nums = [0,-3,7]
Output
[-3,0,7]
Explanation

Negative numbers still follow normal numeric order, so -3 comes first.

Example 3
Input
nums = [10,-5,10]
Output
[-5,10,10]
Explanation

The smallest value moves to the front, while equal values stay as separate entries.

Algorithm Flow

Recommendation Algorithm Flow for Atrium Roster Sorted Signal
Recommendation Algorithm Flow for Atrium Roster Sorted Signal

Solution Approach

A clean way to solve this problem is to sort the array in ascending numeric order and return the result. Since the task is literally to reorder the values from smallest to largest, a direct sorting approach matches the problem exactly.

The main detail to watch is that this is a numeric sort. In some languages, the default sort compares values like text unless you provide a comparator. That can cause wrong results such as placing 18 before 4 just because the character 1 comes before 4. So the important step is to make sure the language sorts by number value, not by string form.

In JavaScript, the core idea looks like this:

nums.sort((a, b) => a - b);
return nums;

The comparator a - b tells the sort that smaller numbers should come first. If a is less than b, the result is negative, so a stays before b. If the numbers are equal, they can stay together, which naturally preserves duplicates in the final array.

This approach handles all of the important cases without extra branches. An empty array remains empty because there is nothing to reorder. A one-element array is already sorted, so the same value comes back. Repeated numbers like [10, -5, 10] become [-5, 10, 10], and nothing gets removed or merged. Negative values also work naturally because numeric comparison already knows that -5 is smaller than 0.

If your language sorts in place, returning the same array after sorting is usually enough for this kind of problem. If you want to avoid mutating the original input, you can make a copy first and sort the copy instead. The overall time complexity is O(n log n), which is the standard cost of comparison sorting, and the extra space depends on the sorting implementation used by the language.

So the whole solution is: take the input array, apply an ascending numeric sort, and return the sorted result exactly as an array of integers.

Best Answers

java
class Solution {
    public boolean atrium_roster_sorted_signal(String[] times) {
        for (int i = 1; i < times.length; i++) {
            if (times[i].compareTo(times[i-1]) < 0) return false;
        }
        return true;
    }
}