Two Albums
InterviewTime limit0.4sMemory limit1024 MB
Given two albums of distinct stamp numbers, find how many numbers appear in both and list them in increasing order.
- Level
Easy3 of 10
- Topics
- Sorting, Hash map, Array, Two pointers
- Solved
- No attempts yet
Problem
You have two albums: one with postage stamps and the other with postage stamps. Within each album all stamps are different, but some stamps appear in both albums. You would like to trade those stamps when you meet other collectors.
Every album stamp has its own unique number: identical stamps have the same number, and different stamps have different numbers.
Write a program albums that determines the number of stamps that appear in both albums, as well as the numbers of the stamps that appear in both the first and the second album.
Input
The first line of the standard input contains two integers and : the number of stamps in the first and second album, respectively.
The second line of the standard input contains different integers : the unique numbers of the stamps in the first album.
The third line of the standard input contains different integers : the unique numbers of the stamps in the second album.
Output
The first line of the standard output must contain a single integer : the number of stamps that appear in both albums.
The second line of the standard output must contain integers in increasing order: the unique numbers of those matching stamps.