Code Logo

Guest Queue with ArrayList

Published at22 Apr 2026
Collections Framework Easy 0 views
Like0

An event desk already has a list of confirmed guests, and a few walk-in guests arrive just before the doors open. The staff wants one final queue that keeps the original confirmed order and then places every walk-in guest after that list.

Your task is to return a new list containing all names from confirmed followed by all names from walkIns. No sorting is needed, and no names should be removed. This is just a clean queue merge where order matters.

For example, if confirmed = ["Ayu", "Bima"] and walkIns = ["Cici", "Dodi"], the result should be ["Ayu", "Bima", "Cici", "Dodi"]. If the walk-in list is empty, the result should simply stay the same as the confirmed list.

This challenge is a friendly way to practice using ArrayList for ordered collection work in Java.

Example Input & Output

Example 1
Input
confirmed = [], walkIns = ["Raka", "Sinta"]
Output
["Raka", "Sinta"]
Explanation

If no guests were confirmed earlier, the walk-ins become the whole queue.

Example 2
Input
confirmed = ["Ayu", "Bima"], walkIns = ["Cici", "Dodi"]
Output
["Ayu", "Bima", "Cici", "Dodi"]
Explanation

The walk-in names are appended after the confirmed list.

Example 3
Input
confirmed = ["Nina"], walkIns = []
Output
["Nina"]
Explanation

No walk-ins means the original order stays unchanged.

Algorithm Flow

Recommendation Algorithm Flow for Guest Queue with ArrayList
Recommendation Algorithm Flow for Guest Queue with ArrayList

Solution Approach

This problem is about preserving order while building one combined list, so ArrayList is a very natural choice. Java lists are designed for exactly this kind of task: keep items in sequence and append more items at the end.

A clean solution is to create a new ArrayList from the confirmed list, then add every element from walkIns. That avoids changing the original input list directly while still giving you the final queue in the correct order.

The core idea looks like this:

List<String> result = new ArrayList<>(confirmed);
result.addAll(walkIns);
return result;

You can also append the second list manually in a loop, which is still valid and helps reinforce how lists grow one element at a time. Either way, the important collection concept is that ArrayList keeps insertion order, so the final queue stays exactly as the desk expects.

The runtime is O(n + m) because each guest from both lists is copied or appended once. Extra space is also proportional to the output list.

Best Answers

java - Approach 1
import java.util.List;
import java.util.ArrayList;

class Solution {
    public static List<String> mergeGuestQueue(List<String> confirmed, List<String> walkIns) {
        List<String> result = new ArrayList<>();
        for (String name : confirmed) {
            result.add(name);
        }
        for (String name : walkIns) {
            result.add(name);
        }
        return result;
    }
}