Merge Two sorted array without extra space

Question link:-https://practice.geeksforgeeks.org/problems/merge-two-sorted-arrays5135/1

Code link:-

Here’s my code for the given question. I have used gapping technique but the problem arises when I am not able to sort the second array. First array always gets sorted. Please, help!

hello @div_yanshu07
image

these lines will not give u ceil because gap is int, ceil of int is same number.
do this
int gap=(n+m)/2 + (n+m)%2 ;
no need of any ceil function now

Now it’s giving more incorrect output. You can look for yourself


GFG judgement;-
“For Input:
4 5
1 3 5 7
0 2 6 8 9
your output is:
1 0 2 3 5 7 6 8 9”

@div_yanshu07
a) image

here also u need to take ceil

b)also u missed one case.
where both elements are from second array.

Handled 'em but now getting TLE.

@div_yanshu07
check now->

Thankyou so much! It works now.

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.