For input [1 5 2] it gives 4 and for [1 2 5] it gives 6.

# Solution in not correct for all the cases

That is correct. For [1 5 2] you give [ 1 2 1] (1+2+1=4) and for [1 2 5] you give [1 2 3] (1+2+3=6).

That is correct. For [1 5 2] you give [ 1 2 1] (1+2+1=4) and for [1 2 5] you give [1 2 3] (1+2+3=6).