# Code Signal – 改变数组(arrayChange)

## 02 Feb Code Signal – 改变数组(arrayChange)

You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input.

Example:

For inputArray = [1, 1, 1], the output should be arrayChange(inputArray) = 3.

Input/Output:

[execution time limit] 4 seconds (js)

[input] array.integer inputArray

Guaranteed constraints:

3 ≤ inputArray.length ≤ 105,

-105 ≤ inputArray[i] ≤ 105.

[output] integer

The minimal number of moves needed to obtain a strictly increasing sequence from inputArray.

It’s guaranteed that for the given test cases the answer always fits signed 32-bit integer type.

class Solution:
def arrayChange(inputArray):
print(inputArray)
minChange = 0

for i in range(1, len(inputArray)):
localDiff = 0
if inputArray[i] <= inputArray[i – 1]:
localDiff = inputArray[i – 1] -inputArray[i] + 1
inputArray[i] += localDiff
minChange += localDiff

print(inputArray)
return minChange
print(arrayChange([1,1,1]))
print(arrayChange([1]))

def solution(inputArray):
number_moves = 0

for i in range(1, len(inputArray)):
# print(“—————-“)
# print(i)
# print(inputArray[i])
if inputArray[i] <= inputArray[i – 1]:
diff = inputArray[i-1] – inputArray[i] + 1
# print(“~~~~”)
# print(diff)
inputArray[i] += diff
number_moves += diff

returnnumber_moves