BudiBadu Logo

Gallery Queue Sort

Sorting Easy 0 views
Like27

In the rooftop gallery's evening preview, security tablets log each guest's badge number as they step off the elevator, but the log reflects the frantic order of arrival instead of the neat flow the hostess expects. The curator has asked for a helper routine that reads the raw badge list and returns a new list where numbers move from the smallest badge to the largest. The original log remains preserved for audits, so the routine must produce a separate, orderly queue that hospitality staff can project on the welcome screen, ensuring every badge is still present while turning the jumble into a calm invitation.

Special access waves sometimes include duplicate badges for paired guests, and maintenance inserts negative placeholders to flag elevator pauses, so the returned queue has to keep every number exactly as it appeared—only arranged in ascending order with no summaries or drop-offs. When an arriving list is already aligned, the hostess should see the same sequence echoed back and know the routine kept a gentle touch. Before doors open, operations compares the helper's output to a trusted reference and halts the preview if any slot is missing or misplaced. Provide a response that matches the reference perfectly, including the quiet case when no badges arrive and the display must stay empty.

Example 1:

Input: nums = [9,3,8,3,1]
Output: [1,3,3,8,9]
Explanation: The guest queue now rises from the lowest badge to the highest while keeping both copies of 3.

Example 2:

Input: nums = [5]
Output: [5]
Explanation: A single badge remains unchanged because it already satisfies the order.

Example 3:

Input: nums = [7,-2,0,7]
Output: [-2,0,7,7]
Explanation: Negative placeholders and repeated badges stay visible in ascending order.

Algorithm Flow

Recommendation Algorithm Flow for Gallery Queue Sort - Budibadu
Recommendation Algorithm Flow for Gallery Queue Sort - Budibadu

Best Answers

java
import java.util.*;
class Solution {
    public int[] sort_queue(int[] nums) {
        int[] res = nums.clone();
        Arrays.sort(res);
        return res;
    }
}