Giving wrong ans in some test cases
You have not considered the fact that An and A1 are also adjacent (It’s a circular list). Consider this testcase
3
10 20 1
Output should be 42 { 10+1 = 11 => (11,20), 11+20 =31 so total penalty=11+31 =42 } but your code is giving 52.
how to add such case in loop??
You can also put the first element after then last element so that it is circular.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.