Mike and Chocolates
Easy Accuracy: 18.61% Submissions: 215 Points: 2

Mike is a seventh grade student and today is his birthday. He wishes to distribute a chocolate each among his friends. He already knows all of his friends have some chocolates with them.
All his friends stand in a straight line. Mike can take all the chocolates of any one of his friend. Find the minimum number of chocolate he should have from the starting so that he can end up in giving minimum of a chocolate each to all his friends. 
He will visit all his friends only once in the order 1,2, ... N.

Input:
First line of input consists of integer T denoting total number of test cases.  First line of each test case contains integer N denoting number of Mike's friends. Second line of each test case contains N space separated integers ( Ai ) denoting number of chocolates the ith friend has.

Output:
Print minimum number of chocolates Mike  should have from the starting for each test case in separate line.

Constraints:
1 <= T <= 2.3*103
1 <= N <= 103
1 <= A<= 103

Example:
Input:
1
6
2 3 1 2 5 2
Output:
3

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.