In this problem, you will be given an array of integers and you need to tell the cost of the cheapest possible subarray of length at least two.
A subarray is the sequence of consecutive elements of the array and the cost of a subarray is the sum of minimum and the maximum value in the subarray.
Note: In an array of length , there are subarrays whose length is atleast 2.
The first line contains a single integer
denoting the number of test cases.
The first line of each test case contains
i.e the number of elements in the array. Next lines contains
lines each containing a single integer.
integer denotes the cost of the cheapest subarray for the
- The only possible subarray of length atleast 2 is [3, 2], Its cost is minimum + maximum = 2 + 3 = 5;
- Three subarrays of lengths at least 2 are possible i.e. [3, 4], [4, 2] and [3, 4, 2]. The minimum possible cost is 6 for the subarrays [4, 2] and [3, 4, 2]