[Here is my solution][1]
[1]: https://www.codechef.com/viewsolution/22955314
You are not considering the corner cases when last and first soldier is attacked.
You are not considering that first soldier could be attacked from 2 and nth soldier together. Same goes for nth soldier.
For first soldier the last soldier will be on his left side and you aren’t checking for that. You can update the if condition to a[(i-1+n)\%n] + a[(i+1)\%n].
1 Like
Let me give you a simple test case and you can spot out your mistake by yourself.
1\\ 3\\ 5 \, 4\, 1 \\ 7\,5 \,5 \\
Your answer in this case is wrong.
Let me give you a simple test case and you can spot out your mistake by yourself.
1\\ 3\\ 5 \, 4\, 1 \\ 7\,5 \,5 \\
Your answer in this case is wrong.