

If the given ‘COINS’ array is [9,6,1,10], then Ninja will collect 10 and 6(Total: 16) and his friend will collect 9 and 1.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer,' N’ denoting the number of sacks in the treasure.
The next line of each test case has ‘N’ values of ‘COINS’.
For each test case, return an integer corresponding to the maximum coins Ninja can collect.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 1000.
1 <= COINS[i] <= 1000
Time limit: 1 sec
In this approach, we will use a recursive function to formulate the answer. We will define a function 'HELPER'(i, j, ’COINS’) that will find the maximum coins that can be collected for the subarray from COINS[i] to COINS[j].
In the previous approach, we just used recursion to find the answer for each sub-problem.
Now we will use dynamic programming to formulate the answer. We will define a function 'HELPER'(i, j, ’COINS’, ’DP’) that will find the maximum coins player can achieve for the subarray from ‘COINS’[i] to ‘COINS’[j]. We will also use memoization and store this value in DP[i][j].
In this approach, we will make a 2D ‘DP’ array of size N*N .’DP’[i][j] will store the maximum amount of coins the player can collect only using the subarray ‘COINS’[i...j]. To fill this ‘DP’ table we will run a loop for ‘GAP’ from 0 to ‘N’.In one iteration of we will fix the values for DP[i][i + ‘GAP’] for all ‘i’. After filling the ‘DP’ table completely, we will return ‘DP’[0][‘N’-1] , the maximum number of coins that can be picked considering the whole array.