Code-:CodeChef: Practical coding for everyone

Question-:MNMX Problem - CodeChef

Hi @jai02 Looking at your code it seems you are just comparing two adjacent elements that is

if the array is [2, 7, 9, 10]

with your approach you will get the answer as

sum=min(2,7)+min(7,9)+min(9,10)=2+7+9=18

but what is asked in question is that the array will change means the value will change too, basically what I mean is the sum should look somewhat like

sum=min(2,7)+min(2,9)+min(2,10)=2+2+2=6

Hint : Sort the array or find the minimum element in the array as that is what would be the result each time between an adjacent pair.