Code Logo

Artisan Display Sort

Published at05 Jan 2026
Easy 0 views
Like23

In Artisan Display Sort, you get an array of integers representing booth numbers and need to return them in ascending order.

The problem is only about order. Do not remove duplicates, do not filter out negative values, and do not transform the numbers into strings or labels. Just take the exact same integers and place them from lowest to highest.

For example, nums = [14,5,12,5] should return [5,5,12,14]. Both copies of 5 remain because the list should keep every original value. Another useful example is nums = [-5,-10,0,5], which should become [-10,-5,0,5]. That makes it clear that normal numeric comparison is what matters, including for negative values.

If the array is empty, the result is empty. If it contains one number, that single value is already sorted. So the task is to order the integers from smallest to largest and return the resulting array.

Example Input & Output

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

A single booth remains unchanged because the ledger was already in order.

Example 2
Input
nums = [14,5,12,5]
Output
[5,5,12,14]
Explanation

Shared booths keep both entries while the list rises from smallest to largest.

Example 3
Input
nums = [9,-2,4,9]
Output
[-2,4,9,9]
Explanation

Negative placeholders and repeats stay visible in ascending order.

Algorithm Flow

Recommendation Algorithm Flow for Artisan Display Sort
Recommendation Algorithm Flow for Artisan Display Sort

Solution Approach

A simple and reliable solution is to use an ascending numeric sort. This problem does not ask for anything extra like counting frequencies, tracking original indices, or checking whether the list is already sorted. You only need the final numbers in low-to-high order, so sorting is the natural answer.

The most important implementation detail is to avoid accidental string-based sorting. In several languages, a default sort can compare values as text unless you tell it not to. That becomes a problem when numbers like 10 and 2 are involved, because text order would incorrectly place 10 before 2. So even for an easy problem, it is worth being explicit about numeric comparison.

In JavaScript, you can write it like this:

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

The comparator a - b ensures the result uses true numeric order. When a is smaller, the result is negative, so a comes first. When the two values are equal, both remain in the array, which is exactly what we want for duplicate booth numbers.

This approach works for every sample shape in the tests. Arrays with repeated values keep those repeats. Arrays with negative numbers place them before zero and positive numbers naturally. Empty arrays return empty arrays because there is nothing to change. Single-element arrays stay the same because they are already sorted.

You do not need nested loops or a custom data structure here unless the problem explicitly asked you to implement a sorting algorithm by hand. For a normal coding challenge at this level, using the language's built-in sort with the correct comparator is completely appropriate and keeps the code short and readable.

The time complexity is O(n log n), which is standard for comparison-based sorting. The space complexity depends on the underlying sorting implementation, but the solution logic itself does not need additional structures beyond the array being sorted.

So the full strategy is: apply an ascending numeric sort, keep every original number including duplicates and negatives, and return the reordered array exactly as the sorted result.

Best Answers

java
import java.util.*;

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