Median of Two sorted Arrays

I write the code without using the sort() function but while submitting the code it pass through only the 1 test case. so, I didn’t get it what mistake I did .
this is link of code https://ide.codingblocks.com/s/194142

Hi @imsaurabh

The code which you have written is trying to perform merge function on two given sorted arrays. And that code for merge function is incorrect. I have made some minor changes, now it works.

Code Link : https://ide.codingblocks.com/s/194152

Hope it Helps.

Hi , can you share a test case where the code fails to merge the array in sorted order.

Consider a case when the length of array is even:
or consider this:
1 2 3 4 5 6
Here median would be the average of 3 and 4.
For this question, follow this optimized approach:

when we merge two arrays then the final array will be the even length but in this question that not the case it always want a number rather than median of two number .

as like Nayan Sachdeva write in their code. you can look into it

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.