Two team rosters each list member IDs in non-decreasing order (a roster may itself contain repeats). Produce the sorted list of every ID that appears in at least one roster, each ID listed exactly once.
Line 1: two integers n and m, the roster sizes.
Line 2: n non-decreasing integers, the first roster.
Line 3: m non-decreasing integers, the second roster.
One line: the distinct IDs from either roster, in non-decreasing order, space-separated.
Example 1
Input
3 3 1 2 4 2 3 5
Expected
1 2 3 4 5
Explanation
IDs appearing in either roster are 1, 2, 3, 4, 5; the shared 2 is listed once.
Example 2
Input
4 2 7 7 8 9 8 8
Expected
7 8 9
Explanation
Roster repeats collapse: the distinct IDs are 7, 8, 9.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →