Optimal game strategy 1

https://ide.geeksforgeeks.org/JH7tfms7WE
https://online.codingblocks.com/app/player/127473/content/109927/4939/code-challenge
my code is giving segmentaton fault.i think the problem is with the if-else statements.i have two if-else statements one to check whether piyush or his friend other to check whether first larger or last but i think only one of them will execute how do i make both of them run?

is this optimal-game-strategy -1 question ??

please tell the question title
the link to course content is not working for me

and the q u have referenced is wrong

yes it is optimal game strategy 1 question

Piyush and Nimit are playing a coin game. They are given n coins with values x1, x2 …. xn where ‘n’ is always even. They take alternate terms. In each turn, a player picks either the first coin or the last coin from the row and removes it from the row. The value of coin is received by that player. Determine the maximum value that Piyush can win with if he moves first. Both the players play optimally. Input Format First line contains the number of coins ‘n’. Second line contains n space separated integers where ith index denotes the value of ith coin. Constraints 1 < N <= 30 , N is always even 0 <= Ai <= 1000000 Output Format Print a single line with the maximum possible value that Piyush can win with. Sample Input 4 1 2 3 4 Sample Output 6 Explanation Piyush will pick the coin 4. Then Nimit can pick either 1 or 3. In both the cases piyush picks coin 2 and wins with a total of 6.

image
u were not adding any base condition

https://ide.geeksforgeeks.org/YHbzKfxxYM it is still failing some testcases

refer to prateek bhaiaya video to understand how the recursion is working here

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.