Your code is O(n^2) which will not pass n=10^5. You need to think of a faster algorithm.

1 Like

Sir, Please can you tell me about batter logic to do this problem ?

You are searching for 2 coins with the least difference. Don’t you think if you sort the array, the coins with the least difference will be together?

Your approach is O(n^2) and hence gives TLE. Try sorting the array and find the min diff possible.

https://www.codechef.com/viewsolution/32706215