Code Logo

Arrange Guest Check-ins

Published at05 Jan 2026
Medium 1 views
Like17

In Arrange Guest Check-ins, you are given an array of integers and need to return the same values sorted in ascending order.

The array may contain duplicates, negative values, zero, or be completely empty. None of that changes the goal. You still keep every original value and just place them from smallest to largest. If the same number appears more than once, both copies should stay in the final array.

For example, arrivals = [12,3,18,3,6] should become [3,3,6,12,18]. Both copies of 3 remain. Another example is arrivals = [-2,-2,7,4,0], which should become [-2,-2,0,4,7]. That makes it clear that negative values belong before larger numbers and duplicates should not be removed.

An empty array stays empty, and a one-element array is already sorted. So the task is simply to reorder the given counts into ascending numeric order and return the result.

Example Input & Output

Example 1
Input
arrivals = [12, 3, 18, 3, 6]
Output
[3, 3, 6, 12, 18]
Explanation

The sorted view places the smallest arrival counts first so the desk schedules staff accordingly.

Example 2
Input
arrivals = [-2, -2, 7, 4, 0]
Output
[-2, -2, 0, 4, 7]
Explanation

Negative values appear first because they reflect cancellations before growth later in the day.

Example 3
Input
arrivals = []
Output
[]
Explanation

An empty clipboard stays empty after sorting because there are no counts to reorder.

Algorithm Flow

Recommendation Algorithm Flow for Arrange Guest Check-ins
Recommendation Algorithm Flow for Arrange Guest Check-ins

Solution Approach

A straightforward numeric sort is enough to solve this problem well. The input is just a list of integers, and the output is the same list arranged in increasing order. Because there is no extra condition beyond that, the cleanest solution is to use a normal sort with a numeric comparator.

The important detail is not to rely on a default text-based sort. In JavaScript, a plain sort() can compare values as strings, which can lead to incorrect ordering for numbers with different digit lengths. To keep the behavior correct for all inputs, you should compare numbers by subtraction.

In JavaScript, the idea is:

const result = [...arrivals].sort((a, b) => a - b);
return result;

Creating a copy first is optional, but it is a nice habit when you want to leave the original input unchanged. The comparator a - b gives you true numeric ordering. Smaller values move earlier in the array, larger values move later, and equal values stay as separate entries.

This is exactly what the examples need. In [12, 3, 18, 3, 6], both 3 values remain after sorting. In [-2, -2, 7, 4, 0], the negative values stay at the front because they are smaller than zero and the positive numbers. Empty arrays stay empty because there is nothing to sort. A one-element array returns that same value unchanged.

This solution is also easier to read than writing your own nested-loop sorting code for a problem like this. The built-in sort already expresses the intent clearly: we want ascending numeric order and nothing more.

The time complexity is O(n log n), which is standard for comparison sorting. Extra space depends on whether you copy the input or sort in place. Either way, the algorithmic idea remains the same.

So the full strategy is: copy the array if needed, sort it numerically from smallest to largest with an explicit comparator, and return the sorted list while preserving duplicates and negative values.

Best Answers

java
import java.util.*;

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