Interesting Coins
Practice
2.5 (6 votes)
Algorithms
Approved
Binary search
Medium
Open
Sorting
Problem
60% Success 678 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Roy has a number of coins with him that he loves playing with by arranging them in the form of N stacks numbered sequentially. Lucy now gives him a task to make his arrangement of coins even more interesting. The arrangement will be interesting if the number of coins in the stacks are in strictly increasing order.

For this task Lucy gives Roy the option to modify his arrangement by increasing or decreasing the number of coins in each of the stack by atmost C coins. Also the number of coins in a stack should not fall below 1.

Your mission, should you choose to accept it, is to report the minimum C that helps Roy complete the assigned task.

Input
First line contains T, the number of test cases

Each test case contains two lines. The first line has a single integer N. The second line contains N space separated integers denoting the number of coins in the stacks initially.

Output
A single line for each test case containing the answer as explained in the statement.

Constraints
1 <= T <= 200
2 <= N <= 1000
The number of coins initially in each of the stack is between 1 and 1000000000.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
11 votes
Tags:
AlgorithmsBinary SearchGreedy AlgorithmsMediumReadySearching
Points:30
8 votes
Tags:
Binary SearchSortingAlgorithms
Points:30
4 votes
Tags:
AlgorithmsBinary Search
Editorial

No editorial available for this problem.