BudiBadu Logo

Festival Cabins Sorted Flag

Sorting Easy 0 views
Like13

During the festival, lodging requests are logged exactly as guests arrive. Coordinators list the cabin names with various casing and spacing. Before the evening rush, the team needs a quick signal to know if the queue is already alphabetical so they can release the ushers. Your task in Festival Cabins Sorted Flag is to return true if the list is sorted case-insensitively, or false otherwise.

The "secret sauce" here is a Linear Comparison Scan. You walk through the list and compare each name to the one before it, making sure to convert them to the same case first. Comparisons should ignore casing, meaning "Star" and "star" are equal. Extra spaces inside names are intentional and should be left alone. If the list is empty, return true. This check provides a reliable flag that keeps the festival walkway clear of last-minute scrambles. It’s a simple, non-destructive way to validate incoming data!

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
cabins = ["Harbor Light","Garden Nook","Harbor Loft"]
Output
false
Explanation

"Harbor Light" should appear after "Garden Nook" when compared alphabetically.

Example 2
Input
cabins = []
Output
true
Explanation

An empty arrival log is already in order, so the ushers can stand down.

Example 3
Input
cabins = ["Aurora Haven","Celestial Loft","glow deck"]
Output
true
Explanation

Each name follows the next alphabetically when casing is ignored.

Algorithm Flow

Recommendation Algorithm Flow for Festival Cabins Sorted Flag - Budibadu
Recommendation Algorithm Flow for Festival Cabins Sorted Flag - Budibadu

Best Answers

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