Input: ‘N’ = 5, ‘NUMS’ = {1, 2, 3, 5, 2}.
Output: 6.

The indices of the chosen elements are [0, 2, 4], hence sum = 1 + 3 + 2 = 6.
Note: Some of the invalid ways to choose the elements are:
Choose the elements with indices (0, 4), it is invalid because, among the pair of indices (1, 2) none of them were chosen.
Choose the elements with indices (0, 2), it is invalid because, among the pair of indices (3, 4) none of them were chosen.
Choose the elements with indices (1, 2), it is invalid because, among the pair of indices (0, 4) none of them were chosen.
The first line will contain the integer 'T', denoting the number of test cases.
The first line of each test case contains an integer ‘N’ denoting the length of the array ‘NUMS.
The second line of each test case contains ‘N’ space-separated integers.
For each test case, you don’t need to print anything just return the minimum adjacent sum
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^6
0 <= NUMS[ i ] <= 10^3
Sum of N Over all the Test cases <= 10^6
Time Limit: 1 sec
In this approach, the idea is to use recursion to optimally find the solution. At each element, we have two choices, either we choose that element or we don’t. Since this is a circular array so we need to take care of the case that when we are including the 0th element then we may or may not choose (‘N’ - 1)th element or when we don’t choose the 0th element then we need to choose the (‘N’ - 1)th element.
We can address this problem by first definitely including the 0th element and then recursively finding the minimum sum from the rest of the element and then we definitely include the (‘N’ - 1)th element and then recursively finding the minimum sum from the rest of the element. The minimum sum is given by the minimum of ( the value we got from including the 0th, the value we got from including the (‘N’ - 1)th element),
To recursively find the minimum sum we can make a recursive function, let the function be ‘F’, the function has two parameters, the index of the elements we are at and a flag value that denotes whether the last element was chosen or not.
If flag = 1 then (i.e, last value was not chosen)
F( idx, flag ) = ‘NUMS[ idx]’ + ‘F( idx+1, 0 ).
Else:
F( idx, flag) = min( ‘NUMS[ idx]’ + ‘F( idx+1, 0 ), F( idx + 1, 1) ).
// Recursive function to get minimum sum.
In this approach, we will be optimizing the previous approach by storing the value of function ‘F’ for arguments (idx, flag) in a matrix, so that we don’t have to calculate the value of the function with the same arguments again and again.
// Recursive function to get minimum sum.
In this approach, We will find the minimum sum for each element and then use that minimum sum to get the value for the next element. For each element, we will calculate the value that we can get by including that element and the value without including that element.
// Iterative function to get minimum sum.