It solves some cases, but the rest is not solved, you can compare the elements and sort it out,
You are just adding the two elements of the var arr
So lets say 1,4 we can loop from 1 to 4 and add the elements, What you have done is finding the max and min value of a single element, in this line and adding through the loop,
which gives a correct answer for items like 1,4 because it flows in an order but what about 4,1, it is descending, therefore you cannot increment the loop, so the test fails for that case
Initially we don’t know which is the max or min element so
Hint: Compare the two elements of the arr and assign the max value to a var and similarly do this for min value and then run the loop from min to max and add those