Stuck in between

how to minimize the difference between the prices i and j… I found out the pairs.

Hi @Riya-Verma-1207263756078812, you can keep a variable and minimise that

Refer this

can you please check my code and tell me where am I wrong… I tried to make a logic… but it’s failing… but when I check the output its correct

@Riya-Verma-1207263756078812,
try this test case
1
3
10 40 70
80

But this testcase is failing for the code you provided too, what are the changes that needs to be made in my code?

@Riya-Verma-1207263756078812, in the above eg i missed value of m that is 80 so it as giving wrong answer actually u r doing minimising thing correctly but you r dividing the array in 2 parts for finding first and second if both are in first half only then the code fails check this
1
5
10 20 40 50 60
30

and here’s the corrected code https://ide.codingblocks.com/s/662988

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.