INTERSECTION OF TWO ARRAY

code–https://ide.codingblocks.com/s/381019
ques–https://hack.codingblocks.com/app/contests/1975/173/problem

hello @aaliyah_beg what is the problem that you are facing?

SIR, when im running it is showing run error

@aaliyah_beg okay wait

hey @aaliyah_beg do you want me to correct your logic as well.
i have corrected the run error from your code.
but your logic is wrong.


please revert if you want to correct the logic as well.

sir i have tried working on the code-- https://ide.codingblocks.com/s/381035

your code is not optimised

hey @aaliyah_beg the logic is simple make the freq array or take the map in which you will count the frequency for the elements of both the arrays and then you will make the comparison on the fre arrays for both the arrays and for the particular number the min of both the frequencies is the intersection for the particular element in the arrays.

I have understood the optimised way but sir shouldn’t my code also work correctly , the right output aint coming .

i have not even understood your approach.

hey @aaliyah_beg your logic is wrong when you are checking a[i]==b[j] it will edit for as many number of times as it will the same number in b array. this way you will not be able to find the intersection of the array.

also the the array length can be of order 1e6 so if you apply this logic then it will give you TLE.
as it is taking O(N^2) time to do this.