Common Elements
InterviewTime limit2sMemory limit1024 MB
Given two short integer sequences, print every value that occurs in both, once each, in ascending order.
- Level
Easy2 of 10
- Topics
- Hash map, Sorting, Implementation
- Solved
- No attempts yet
Problem
You are given an integer sequence A = (A1, A2, ..., AN) of length N and an integer sequence B = (B1, B2, ..., BM) of length M. Print every integer that appears in both A and B, each exactly once, in ascending order.
Input
The input is given from standard input in the following format.
N M
A1 A2 ... AN
B1 B2 ... BM
Output
Print every integer that appears in both A and B, each exactly once, in ascending order. Separate each integer with a newline.
Constraints
1 ≦ N ≦ 100.1 ≦ M ≦ 100.1 ≦ Ai ≦ 100(1 ≦ i ≦ N).1 ≦ Bj ≦ 100(1 ≦ j ≦ M).