Find Intersection of Two Arrays - Java Code

preview_player
Показать описание
Write a java program to find intersection of two arrays.
Write a java program to find common elements in two arrays.

Given two sorted arrays, Write a java code to find intersection of two arrays. For example, if the input arrays are:

arr1[] = {2, 3, 6, 7, 9, 11}
arr2[] = {4, 6, 8, 9, 12}

Then your program should print intersection as {6, 9}

Рекомендации по теме
Комментарии
Автор

The way you have explained two approaches to solve this problem is awesome.

Amitkumar-lyzl
Автор

Nice video but one minor correction: You should state explicitly that your first O(m+n) solution works ONLY for sorted arrays. The failing test case is [6, 1, 2, 3] and [1, 2, 3]. Your second O(m+n) solution works for both types of arrays obviously.

abhibhagat
Автор

how do we ignore repeated number for eg arr1=[1, 2, 3, 4, 5] arr2=[1, 1, 2, 2, 3] output= 1, 1, 2, 2 but desired output =[1, 2]

mohitkatyal
Автор

What if the 2nd array contains 2 values which are same. It would be printed 2 times which is wrong

Mrdeep
Автор

same as two array of tunion example can you explain sir

ganeshc
Автор

What if array is not sorted.. Then which approach will you use

sanket
Автор

Code link is present in the description box.

ProgrammingTutorialsM
Автор

Can u pls tell me the platform u r using sir or the software

ad_cy
Автор

This program will not pass all cases it consists of so many bugs

Liv_Life
Автор

You're finding common elements, this is not intersection.

raminanushiravani
join shbcf.ru