Loading...
Loading...
Two clubs each have a member list of roll numbers (a list may repeat a number by mistake). Print the roll numbers in both clubs, and then the roll numbers in at least one club. Print each number once, in ascending order.
NONE if there are none. Line 2: all roll numbers from both clubs.Example 1
Input
5 4 1 7 4 9 4 9 3 4 8
Output
4 9 1 3 4 7 8 9
4 and 9 are in both clubs; the repeated 4 is printed once.
Example 2
Input
2 1 2 2 3 4
Output
NONE 1 2 3 4
No one is in both clubs.
Try the problem first. Open one hint at a time.
Sort both lists with Arrays.sort. Then equal numbers line up and repeats sit next to each other.
Walk both lists with two indexes, like merging. Equal fronts go into both answers; otherwise the smaller front goes only into the combined list.
Before printing a number, skip it if it equals the last number printed on that line.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor