Intersection of Two Arrays II

Given two integer arrays ARR1 and ARR2 of size N and M respectively, find the intersection of these arrays. An intersection refers to elements that appear in both arrays.

Note:
Input arrays/lists can contain duplicate elements. The intersection elements returned should be in the order they appear in the first array/list (ARR1).

Example:

Input:
t = 1 
N = 3
ARR1 = [1, 2, 2]
M = 2
ARR2 = [2, 3]
Output:
2
Explanation:

The element '2' is common in both arrays and appears in the first array.

Constraints:

  • 1 ≤ t ≤ 102
  • 0 ≤ N ≤ 105
  • 0 ≤ M ≤ 105
  • Time Limit: 1 second.
Be the first one to answer
Add answer anonymously...
Hexaware Technologies Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter