Guest Queue with ArrayList
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
If no guests were confirmed earlier, the walk-ins become the whole queue.
The walk-in names are appended after the confirmed list.
No walk-ins means the original order stays unchanged.
Algorithm Flow

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:
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
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;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
