Medium
Accuracy: 49.03%
Points: 4
You are given an array arr of size n. The elements of the array represent n coin of values v1, v2, ....vn. You play against an opponent in an alternating way. In each turn, a player selects either the first or last coin from the row, removes it from the row permanently, and receives the value of the coin. You need to determine the maximum possible amount of money you can win if you go first.
Note: Both the players are playing optimally.
Input:
n = 4
arr[] = {5, 3, 7, 10}
Output:
15
Explanation: The user collects maximum
value as 15(10 + 5)
Input:
n = 4
arr[] = {8, 15, 3, 7}
Output:
22
Explanation: The user collects maximum
value as 22(7 + 15)
- Complete the function maximumAmount() which takes an array arr[] (represent values of n coins) and n as number of coins as a parameter and returns the maximum possible amount of money you can win if you go first.
O(n*n)
O(n*n)
2 <= n <= 10^3
1 <= arr[i] <= 10^6