-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel17.py
More file actions
35 lines (22 loc) · 1018 Bytes
/
level17.py
File metadata and controls
35 lines (22 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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.
def solution(inputArray):
counter = 0
for i in range(len(inputArray)-1):
if inputArray[i+1] <= inputArray[i]:
diff = inputArray[i] - inputArray[i+1]
counter+=(diff+1)
inputArray[i+1] = inputArray[i+1] + diff + 1
return counter
# alternate solution
# def solution(inputArray):
# #[1, 1, 1], exactly one chance +1 per move
# #find minimal number of moves
# moves_min = 0
# for i in range(len(inputArray)-1):
# if inputArray[i]<inputArray[i+1]:
# continue
# else:
# while inputArray[i]>=inputArray[i+1]:
# moves_min += (inputArray[i]-inputArray[i+1])+1
# inputArray[i+1] += (inputArray[i]-inputArray[i+1])+1
# return moves_min