Mike and Chocolates
Submissions: 208   Accuracy:

18.77%

  Difficulty: Easy   Marks: 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*10^3
1<=N<=10^3
1<=Ai<=10^3

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

** For More Input/Output Examples Use 'Expected Output' option **

Author: ShivamKD


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.