My code is not passing the test cases please help

you should have to declare q1 and q2 inside the for loop
because they should be redeclare in each iteration
other previous testcase value will mix with current testcase values

also breakdown you code into only 3 cases
case1(left side heap has more elements)
case2(both heaps are balanced)
case3(right side heap has more elements)
in each case check the current value with prev median and do accordingly

Reference Code

please see this code once and tell where i am doing mistake

i got my mistake !! thanks for helping me

i have another doubt ?
why this logic is incorrect either it is giving me the correct answer

it will not work for all testcases
only work for some testcases

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.