Https://ide.codingblocks.com/s/186802

What is wrong in this code ?
i passed sample test case.
please help

your code fails for some test case:

20
22 138 57 138 137 107 71 61 2 20 25 80 31 127 113 90 148 136 54 69
160

please work it out, o/p is
Deepak should buy roses whose prices are 22 and 138.
ur code produces 80 80

try updating the code, if u fail to do so, ping me i`ll help u

I updated code and its works but just have query regrading testcase:
here in problem statement " If there are multiple solutions print the solution that minimizes the difference between the prices i and j"

that lines means we should pick the pair which has minimum difference so in that above case 80 80 has difference 0 so i picked up that one.

So could you please explain ?

we dont have 2 ( 80 ) . u are duplicating the value i suppose in the code , there is just 1 80 in that array

ohh got your point thanks

1 Like