7 kyu

Simple Fun #67: Array Change

229 of 494myjinxin2015

Description:

Task

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 arr = [1, 1, 1], the output should be 3.

Input/Output

  • [input] integer array arr

    Constraints:

    3 ≤ inputArray.length ≤ 100,

    -10000 ≤ inputArray[i] ≤ 10000.

  • [output] an 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.

Puzzles

Stats:

CreatedFeb 3, 2017
PublishedFeb 3, 2017
Warriors Trained1033
Total Skips12
Total Code Submissions1109
Total Times Completed494
JavaScript Completions211
C# Completions72
Python Completions229
Ruby Completions35
Total Stars15
% of votes with a positive feedback rating92% of 146
Total "Very Satisfied" Votes127
Total "Somewhat Satisfied" Votes15
Total "Not Satisfied" Votes4
Total Rank Assessments10
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • jhoffner Avatar
  • kazk Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad