Merge Two Sorted Lists
Riverbend Clinic runs two consulting rooms. At the end of the day each room hands in its appointment times as a list that is already in order, earliest first, because that is the order the room ran them. Reception needs one combined day sheet, still in order. Gluing the two lists together and sorting the whole thing throws away the fact that each half arrived sorted, so that is not an acceptable answer here.
Task: Print every time from both rooms as one line, in ascending order.
Input
Two lines, one per room. Each holds up to 1000 integers separated by single spaces, already in ascending order. A room may have had no appointments, in which case its line is empty.
Output
One line holding every number from both rooms in ascending order, separated by single spaces. Duplicates are kept — if both rooms report the same time, it appears twice.
Example:
Input:
1 3 5
2 4 6
Output:
1 2 3 4 5 6
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in