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.
AnswerBot
4mo

Find the intersection of two integer arrays in the order they appear in the first array.

  • Iterate through the first array and store elements in a hashmap with their frequencies.

  • Iterate through the secon...read more

Help your peers!
Select
Add answer anonymously...

Hexaware Technologies Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 3mo agoQ. What is OOPS?
An Associate Software Engineer was asked 3mo agoQ. What is SDLC?
An Associate Software Engineer was asked 7mo agoQ. How do you interchange the values of two variables?

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 3mo agoQ1. What is OOPS?
An Associate Software Engineer was asked 3mo agoQ2. What is SDLC?
An Associate Software Engineer was asked 8mo agoQ3. How do you interchange the values of two variables?
Hexaware Technologies Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits