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.
For inputArray = [1, 1, 1], the output should be
arrayChange(inputArray) = 3.
function arrayChange(inputArray) {
let increaseCount = 0;
let totalCount = 0;
for(i = 0; i < inputArray.length; i++) {
if (inputArray[i+1] - inputArray[i] < 1) {
increaseCount = (inputArray[i] - inputArray[i+1] + 1);
totalCount += increaseCount;
inputArray[i+1] += increaseCount;
}
}
return totalCount;
}
function arrayChange(inputArray) {
return inputArray.reduce(function(x,b,i,a){
while(b >= a[i+1]){x++; a[i+1]++;};
return x;
},0)
}
function arrayChange(series) {
var moves = 0;
for (var i = 1; i < series.length; i++) {
if (series[i] <= series[i - 1]) {
diff = series[i - 1] - series[i] + 1;
series[i] += diff;
moves += diff;
}
}
return moves;
}