sol: https://ide.codingblocks.com/s/381997
prob: https://hack.codingblocks.com/app/contests/1975/173/problem
Is this the correct approach
Hey @raghav007
No its not
assume
two arrays are
1 1
1 1 1
then u will add 1 to list 6 times
but it should be added 2 times only
Correct Approach
store frequency of all elements of first array in map.
and then iterate second array see whether its frequency in map is greater than 0 or not.
if it is then include that element in ur answer and decrease the frequency by 1.
is it possible to do it any other way just using array
Yes there is if u know the range of elements say [a,b] but complexity will be O(n*m) in it
for(i=0 to n) //1sr array
for(j=0 to m) //2nd array
if(array1[i] == array2[j])
add it to list
array2[j]= a-1//set out of range element so don't itersect with other
break;//go to next element of 1st array
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.