Loyal Customers Across Two Days
EasyAsked in:Amazon•Stage:Onsite
hash_tablesorting
Problem Statement
Given the list of customer IDs who made a purchase on day 1 and the list for day 2, identify all customers who bought on both days and output their IDs in ascending order.
Input Format
Two integers n and m denoting the number of purchases on day 1 and day 2 respectively, followed by n integers (day 1 IDs) and m integers (day 2 IDs). All IDs are 32‑bit signed integers.
Output Format
Print the loyal customer IDs in increasing order, separated by spaces. If none exist, print nothing or an empty line.
Constraints
- 1 <= n <= 10^5
- 1 <= m <= 10^5
- Customer IDs are integers in the range 1 to 10^9
- Arrays may contain duplicate IDs