Two player X and Y are playing a game in which there are pots of gold arranged in a line, each containing some gold coins. They get alternating turns in which the player can pick a pot from one of the ends of the line. The winner is the player who has a higher number of coins at the end. The objective is to maximize the number of coins collected by X, assuming Y also plays optimally. You are required to complete the method **maxCoins** which returns an integer denoting the max coins X could get while playing the game. You may assume that X starts the game.

**Input:**

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer denoting the no of gold pots. Then in the next line are N space separated values denoting the values (A[]) of gold coins in each pot.

**Output:**

For each test case in a new line print the maximum amount of money X can collect.

**Constraints:**

1<=T<=100

1<=N<=100

1<=A[]<=1000

**Example(To be used only for expected output):
Input:**

2

4

8 15 3 7

4

2 2 2 2

22

4

Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.