Dude Your Time Complexity is N^2logN^2 try reducing it to O(N^2) !!
Spoiler
Instead of Taking B array of size 100000000 Take ‘Count’ array of size N+1 since MEX of the array can be [0, N] so each time u get a MEX, update the count of MEX
Now you have count of each number .i. e. how many times each number is MEX now you can just iterate on count array and find kth small MEX;
sir,what is the use of a[r] in cnt[a[r]]++,i means what is the value of a[r] in cnt[a[r]] in loop,as we dont assign any value in this vector a[maxn]
replie kindly m doubt