Find Intersection Of Two Unsorted Arrays

preview_player
Показать описание
JOIN ME
—————

COMPLETE PLAYLIST
————————————

INTERVIEW PLAYLIST
————————————

QUICK SHORT VIDEOS
————————————-

Time Lines
=========
0:05 Introduction
0:56 Approach

In this video we will learn how to find intersection between two unsorted arrays with best time complexity of O(n+m) and just space complexity of O(n).

This is one of the important interview questions and interviewers do expect you to solve it with good complexity, so hey go with this video and let me know if there is any doubt, we can discuss in the comment section.

#array #unorder_set #stl #dsa #algorithms #datastructure
Рекомендации по теме
Комментарии
Автор

Using unorederd map will be best if they ask to print repetition of numbers present in both arrays

gamedeeds
Автор

Dear Rupesh, I sensed that you are missing the fact that you can blindly keep inserting element in UnSet, w/o checking if exists or not. UnSet.insert() will return non zero for dup insert attempt which can be counted for intersection. So just O(n+m) i.e. O(n) you get answer.

aby_yadav
Автор

Dear Sir, why the following code is giving error, if I am not using const in copy constructor?
#include <iostream>
using namespace std;
class Base{
int x;
public:

Base(int
Base(Base&
};

Base getInstance(){
Base b;
return b;
}
int main()
{
Base b=getInstance();
return 0;
}

AJAYKUMAR-glvx
Автор

There is one thing I want to ask, will this approach work if there is repetition of elements in the arr1.

FANSasFRIENDS
Автор

Just go on removing the elements from the set when ever you find it, what you said in the video will give wrong answer when you have duplicate elements in array1

anirudh