There is a student who wants to assign a value to an array of N integers. He has to assign at least value of 1 to every number. For every two integer numbers at adjacent positions, the one with the higher integral value should be assigned a higher value. He wants to assign the least/minimum amount of values in total. find the minimum value in total assigned to the integers.
The first line of the input contains an interger T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains an integer N denoting the size of the array.The second line of each test case contain N space separated integers.
Output the desired result corresponding to each test case in a separate line.
1 <= T <= 100
1 <= N <= 100
1 <= A[i] <= 10^5
1 2 3 4
2 4 4
2 1 3 2 4
First test case:
First number is assigned a value = 1. Second number is at adjacent position to first number and has higher integral value. So, it should be assigned with higher value. So, he assigned second number a value of 2. Similarily he assigned third and fourth number, values of 3 and 4 respectively.
Therefore, in total, 1+2+3+4 =10
Second test case:
First number is assigned a value of 1. Since second number is greater than than the first number, he assigned a value of 2. Third number is equal to second number. So, it can be assigned a lower value. So, assigned a value of 1.
hence 1+2+1 = 4
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.