반응형
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. |
code>>
int arrayChange(std::vector<int> inputArray) {
int count = 0;
for (int i = 1; i < inputArray.size(); i++)
{
if (inputArray[i] <= inputArray[i - 1])
{
count += inputArray[i - 1] + 1 - inputArray[i];
inputArray[i] = inputArray[i - 1] + 1;
}
}
}
반응형
'알고리즘 > codefights' 카테고리의 다른 글
19>areEquallyStrong (0) | 2017.07.02 |
---|---|
18>palindromeRearranging (0) | 2017.07.02 |
16>areSimilar (0) | 2017.06.28 |
15>addBorder (0) | 2017.06.28 |
14>alternatingSums (0) | 2017.06.28 |