

Let's say we have an 'ARR' = {1, 2, 3, 4}, so the possible complete
binary trees will be:
4 12
/ \ / \
1 8 6 4
/ \ / \
2 12 2 3
/ \ / \
3 4 1 2
Sum of non-leaf nodes = 24 Sum of non-leaf nodes = 20
So the required answer you have to return is 20.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of every test case contains an integer ‘N’ denoting the number of array elements.
The second line of every test case contains 'N' space-separated integers denoting the inorder traversal of leaf nodes of a complete binary tree.
For each test case, return the minimum possible sum of non-leaf nodes of a binary tree.
Output for each test case is printed on a separate line.
1.You do not need to print anything, it has already been taken care of. Just return the minimum possible sum of all non-leaf nodes.
2. It is guaranteed that the answer fits into a 32-bit signed integer (ie. it is less than 2^31).
1 <= T <= 10
2 <= N <= 40
1 <= ARR[i] <= 15
Where ‘ARR[i]’ represents the array elements.
Time limit: 1 sec
The steps are as follows:
{6,2,4,8} ‘ANS' = 0
{6,4,8} ‘ANS’ = 8 (2*min(6 , 4))
{6,8} ‘ANS’ = 8 + 24(4*min(6 , 8))
{8} ‘ANS’ = 8 + 24 + 48(6*8)