Median of sorted array

please have a look on my code…i tried this problem without using the extra space so its getting passed all the testcases but when i am trying to think of the possible test cases then this logic is failing.
please correct me…