Help me out in this problem



it is giving wa on leetcode

@KartikKhariwal are u there ?

yeah checking wait …

Hey I think u are assuming diff is always positive ,correct me if I am wrong :slight_smile:

So its not working because three elements cant have the same index, i.e i ,j and mid should be different but ur code is not taking care of that

@Kartikkhariwal1 https://ide.codingblocks.com/s/361678
it is passing 112 test cases out of 121

@Kartikkhariwal1 bro two for loop then third one i am implementing binary search in such a way that required difference is close to it

Take this outside loops

           int mn=INT_MAX;

I think this is self explanatory :slight_smile:

@Kartikkhariwal1 yes bro i always made this stupid mistake can you tell me ways to reduce it

???/

urs is O(n^2 log n) u can do it in O(n^2) ,see the solutions page of the question .