

You are given ‘MARKS’ = [7, 10, 9, 5], Here you can distribute candies as [1, 3, 2, 1]. Here all the students with higher marks than the students sitting beside them also have more candies. Hence the answer is 7.
The first input line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing the number of students.
The second line of each test case contains ‘N’ space-separated integers, representing the marks of each student.
Print a single integer for each test, representing the minimum number of candies required to distribute to all students.
Print a separate line for each test case.
1 ≤ T ≤ 10
1 ≤ N ≤ 10000
0 ≤ MARKS[i] ≤ 10^5
Time Limit: 1 sec.
You do not need to print anything. It has already been taken care of. Just implement the given function.
In this approach, we will try to start with distributing one candy to each child and then check if any child who has more rating than one of the neighbours should have more candy than its neighbour. So, distribute one more candy to that child who does not satisfy the above condition. Do this until every child is satisfied.
Algorithm:
In this approach, we will first try to only match the given condition from the left side and then from the right side. First, we give 1 candy to everyone and traverse the array from left to right. If a student has more marks than the student on his left side we increase the current student’s candy to be one more than the left student. Then we do the same thing for the student in right while traversing the array from right to left.