A New Year Game
Submissions: 529   Accuracy:


  Difficulty: Easy   Marks: 2

Rahul and his friends decided to play a game in a New Year Party and the winner will be given some cash prize as decided among them.The game is as follows:-

1.N carpets will be arranged in a row and each of them will have a number written on it.

2.A basket full of chocolate is kept there and a person has to take out M chocolates from the basket before starting the game.

3.A person with M chocolates will start at the first carpet ,eat one chocolate and move to the second one,then again eat one chocolate and move to the third one...and so on..

4.If on reaching any carpet ,the number of chocolates in the persons hand is less than the number written on the carpet ,then that  person loses the game.

Find the minimum number of chocolate Rahul should take out of the basket to ensure that he wins the game.

Note:Number of chocolates and the number written on the carpet are compared before the person eats the chocolate on that carpet.See the examples given :)


The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains a single integer N denoting the number of carpets. The second line contains N space-separated integers W1W2, ..., WNdenoting the numbers written on the carpets.



For each test case, output a single line containing the minimum numer of chocolate Rahul should take out of the basket.


  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 10^5
  • 1 ≤ Wi ≤ 10^6


6 5 4 3 2
3 4 3 1 1


Test case 1:

If Rahul takes 6 chocolates, on the first step we have 6 >= 6 everything is OK, then after he ate one chocolate ,  the chocolates decreased to 5 and on the 2nd carpet we'll receive 5 >= 5, again OK, and so on.

Test case 2:

If Rahul takes 4 chocolates, then he will loose the game on reaching the 2nd carpet .

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

Contributor: RIYA BHARDWAJ
Author: Riya Bhardwaj

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.