I don't know what i am doing wrong
Hello @sarthaksingh,
Your code works fine for n=4 but produces a wrong output for n>=6.
Example:
6
1 2 3 4 5 6
Expected Output:
12
Your Output:
38
To better understand your mistake, dry run your code using pen and paper.
Hope, this would help.