BudiBadu Logo

Gallery Stock Order Check

Stack Easy 1 views
Like20

The grand gallery receives shipments of sculptures labeled with sequence numbers, but the crates often arrive in a random scramble. In Gallery Stock Order Check, your task is to take the arrival log and produce a fresh list where the sculpture IDs are sorted from the smallest value to the largest. This lets the curators plan the exhibit walkthrough much more effectively!

The "secret sauce" here is Non-Destructive Sorting. You need to build a brand-new copy of the list so the original dock receipts remain untouched for auditing. Your routine must handle everything: duplicate IDs for set pieces and negative placeholders for items still in customs. Every single ID must be accounted for in the final rising order. If the shipment is already orderly, just return a clean, sorted copy. This simple transformation ensures the gallery opening stays on schedule and that every piece is right where it belongs!

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
widths = [12,18,18,21]
Output
true
Explanation

The widths never decrease, so the rack can move directly to the gallery floor.

Example 2
Input
widths = [24,19,20]
Output
false
Explanation

The second entry breaks the nondecreasing order, signalling a rearrangement is needed.

Example 3
Input
widths = []
Output
true
Explanation

An empty manifest is trivially ordered, so the crew can proceed when the shipment arrives.

Algorithm Flow

Recommendation Algorithm Flow for Gallery Stock Order Check - Budibadu
Recommendation Algorithm Flow for Gallery Stock Order Check - Budibadu

Best Answers

java
class Solution {
    public boolean is_gallery_ordered(int[] nums) {
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i+1]) return false;
        }
        return true;
    }
}