BudiBadu Logo

Arrange Guest Check-ins

Sorting Medium 0 views
Like17

The objective is to reorder a collection of guest arrival counts, represented as an array of integers, into a strictly non-decreasing sequence. This task ensures that records are organized from the lowest frequency of arrivals (including negative values representing net departures) to the highest, providing a clear visualization of peak and off-peak periods.

The final output must be a new array containing all original numerical entries in ascending order. The solution must handle duplicate values by maintaining their relative grouping and gracefully manage empty input arrays. This ensures data integrity while preparing the logs for resource planning and staff allocation analysis.

Example 1:

Input: arrivals = [12, 3, 18, 3, 6]
Output: [3, 3, 6, 12, 18]

Example 2:

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

Example 3:

Input: arrivals = []
Output: []

Algorithm Flow

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

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;
    }
}