Counting Removal Game

Two players play a game with an array of n integers arranged in a row. On each turn, a player takes either the leftmost or the rightmost remaining element and adds its value to their total score. The game ends when no elements remain.

Both players play optimally to maximize their own total score. Given the array, compute the maximum total score the first player can achieve.

Examples
Input: [1,2,3,4]
Output: 6
Hints

Counting Removal Game

Two players play a game with an array of n integers arranged in a row. On each turn, a player takes either the leftmost or the rightmost remaining element and adds its value to their total score. The game ends when no elements remain.