AmazonOA #187
Find Recurring Names
Estimated EasyJudge-ready
No two real names are anagrams of each other, and every registered name is an anagram of some real name. Find the real names registered more than 1 time and output them in lexicographic order; if there are none, output None. Repeated identical registered names each count as a separate account.
Input
The first line contains n m, followed by n lines of real names and m lines of registered names. 1≤n,m≤100000; each name has length 1..10 and contains only lowercase letters; real names are distinct and no two are anagrams of each other.
Output
Output on one line, in lexicographic order, the real names that were registered repeatedly, separated by spaces; if there are none, output None.
Example 1
Input:
3 3
rohn
henry
daisy
ryhen
aisyd
henry
Output:
henry
Example 2
Input:
2 5
tom
jerry
reyjr
mot
tom
jerry
mto
Output:
jerry tom
Example 3
Input:
1 1
abc
bca
Output:
None
Example notes
The answers are henry; jerry tom; None.
Editorial
Loading solution…