Convert to Strictly increasing array
Submissions: 3164   Accuracy:

19.85%

  Difficulty: Hard   Marks: 8

Given an array A of N positive integers. Find the minimum number of operations (change a number to greater or lesser than original number) in array so that array is strictly increasing (A[i] < A[i+1]).

Note : The array should remain array of integers.  For example, consider {6, 9, 7}, we cannot insert 6.x between and 7.

Input:
First line consists of T test cases. First line of every line test case consists of N, denoting number of elements in array. Second line of every test case consists of array elements.

Output:
Single line output, print the minimum operations to be done to make it strictly increasing.

Constraints:
1 <= T <= 106
1 <= N <= 106
1 <= Ai <= 108

Example:
Input:

2
6
1 2 3 6 5 4
7
1 2 3 4 5 6 7
Output:
2
0
Explanation:
Testcase 1:
Only 5 and 4 need to changed to some larger value to make the array strictly increasing.

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

Contributor: Admin
Author: saksham seth


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

to report an issue on this page.