Unable to understand the ques

why ans is 6 , it should be 7 , and pls tell why code is giving segmentation error !!!

hello @Shubham800

both players are equally smart.
4
1 2 3 4

if player1 will pick 4 then player2 will pick 3
then again player1 will pick 2 and then player2 will pick 1
so player1 score in the end will be 4 +2 =6.

which code? pls save it on cb ide and share it with me

https://ide.codingblocks.com/s/417847 it is my code pls tell me why it is giving segmentation error, pls correct it and commen there only in code

ur logic is incorrect.

reason for seg fault->
image

here u r not checking i+1 < n condition and j-1 >=0 condition