I am getting the correct output but I used a different approach to solve the problem and I am getting wrong answer .

please look for any possible cases where it might fail .

I am getting the correct output but I used a different approach to solve the problem and I am getting wrong answer .

please look for any possible cases where it might fail .

I don’t know what exactly your approach is but i think you want to find the minimim number of elements that you need to change. For that you would need to find the smallest of all total_diff values throughout the loop , i.e. total_diff = min (total_diff, N-count) . I would have tried it myself but i couldn’t find the problem in your submissions.

And next time describe what your approach is.

Thanks for replying .

I just made a few test cases and tried to build a logic but the answer was not being accepted .

I saw the solution and it was clear .

Practice problem - Make all equal using Pairs - Problems | CodeChef

This is the problem .