BudiBadu Logo

Festival Stall Order

Array Easy 4 views
Like19

At the downtown night festival, stall identifiers arrive in a jumbled order. The event director needs a helper routine that takes this list and returns a fresh version where every value rises from the smallest stall number to the largest. Crucially, the original tablet record must remain untouched, so your routine returns a brand-new list for the signage crew to follow.

The "secret sauce" here is Ascending Sorting. Vendor collectives might share the same stall number, and marshals use negative placeholders for closed lanes. Your returned list must preserve every single entry—duplicates and all—only repositioning them into a clean, ascending order. If the data is already in sequence, just return a copy of the list. This ensures the director can arrange lighting and checkpoints without any confusion. It’s a fast, reliable way to organize event data into a predictable, usable format for the team!

If sorting is part of the strategy, do it intentionally as a preprocessing step to simplify downstream logic such as merging, ordering, or comparison. After sorting, keep output semantics precise: preserve expected structure, avoid dropping valid entries, and ensure tied cases still follow deterministic order rules.

Examples

Example 1
Input
nums = [13]
Output
[13]
Explanation

A single stall stays unchanged because the identifiers were already ordered.

Example 2
Input
nums = [21,8,21,4]
Output
[4,8,21,21]
Explanation

Shared stalls keep both entries while the list climbs from smallest to largest.

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

Negative placeholders and duplicates remain visible in ascending order.

Algorithm Flow

Recommendation Algorithm Flow for Festival Stall Order - Budibadu
Recommendation Algorithm Flow for Festival Stall Order - Budibadu

Best Answers

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