You are given N counters, initially set to 0, and you have two possible operations on them:
- increase(X) − counter X is increased by 1,
- max counter − all counters are set to the maximum value of any counter.
A non-empty array A of M integers is given. This array represents consecutive operations:
- if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
- if A[K] = N + 1 then operation K is max counter.
For example, given integer N = 5 and array A such that:
A[0] = 3 A[1] = 4 A[2] = 4 A[3] = 6 A[4] = 1 A[5] = 4 A[6] = 4the values of the counters after each consecutive operation will be:
(0, 0, 1, 0, 0) (0, 0, 1, 1, 0) (0, 0, 1, 2, 0) (2, 2, 2, 2, 2) (3, 2, 2, 2, 2) (3, 2, 2, 3, 2) (3, 2, 2, 4, 2)The goal is to calculate the value of every counter after all operations.
Write a function:
def solution(N, A)
that, given an integer N and a non-empty array A consisting of M integers, returns a sequence of integers representing the values of the counters.
Result array should be returned as an array of integers.
For example, given:
A[0] = 3 A[1] = 4 A[2] = 4 A[3] = 6 A[4] = 1 A[5] = 4 A[6] = 4the function should return [3, 2, 2, 4, 2], as explained above.
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..N + 1].
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [1, 0, 1, 4, 0] 2 [1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res1[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [1, 0, 1, 4, 0] 2 [1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [1, 0, 1, 4, 0] 2 [1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
#print tmp_res
#print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
#print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [1, 0, 1, 4, 0] 2 [1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [1, 0, 1, 4, 0] 2 [1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
print tmp_res
print res
print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [1, 0, 1, 4, 0] 2 [1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if res[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if tmp_res1[x] < max_counter:
tmp_res1[x] = max_counter + tmp_res[x]
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[1, 0, 0, 2, 0] [3, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
for x in xrange(len(res)):
tmp_res1[x] = res[x] - tmp_res[x]
if tmp_res[x] < max_counter:
tmp_res[x] = max_counter
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[2, 2, 2, 2, 2] [0, 0, 1, 2, 0]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
tmp_res1 = tmp_res
for x in xrange(len(res)):
if tmp_res[x] < max_counter:
tmp_res[x] = max_counter
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[2, 2, 2, 2, 2] [2, 2, 2, 2, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
tmp_res1 = tmp_res[:]
for x in xrange(len(res)):
if tmp_res[x] < max_counter:
tmp_res[x] = max_counter
#print tmp_res
#res[x] = res[x] + tmp_res[x]
print tmp_res
print tmp_res1
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
[2, 2, 2, 2, 2] [1, 0, 0, 2, 0]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
tmp_res1 = tmp_res[:]
for x in xrange(len(res)):
if tmp_res[x] < max_counter:
tmp_res[x] = max_counter
res[x] = tmp_res[x] + tmp_res1[x]
print res
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
WARNING: producing output may seriously slow down your code! [3, 0, 1, 4, 0] [3, 2, 1, 4, 0] [3, 2, 2, 4, 0] [3, 2, 2, 4, 0] [3, 2, 2, 4, 2]
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
max_counter = max_val
for y in xrange(lenA-1, 0, -1):
if A[y] == n1:
# print tmp_res
# print res
# print max_counter
tmp_res1 = tmp_res[:]
for x in xrange(len(res)):
if tmp_res[x] < max_counter:
tmp_res[x] = max_counter
res[x] = tmp_res[x] + tmp_res1[x]
break
else:
tmp_res, tmp_max_val = increase(A[y], tmp_res, tmp_max_val)
return res
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
tmp_res = [0] * N
tmp_res1 = [0] * N
tmp_max_val = 0
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
res = max_counter(max_val, N)
return res
Traceback (most recent call last): File "user.py", line 117, in <module> result = solution ( N, A ) File "user.py", line 28, in solution res = max_counter(max_val, N) TypeError: 'int' object is not callable
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
max_counter = 0
lenA = len(A)
n1 = N+1
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
res = max_counter(max_val, N)
return res
Traceback (most recent call last): File "user.py", line 114, in <module> result = solution ( N, A ) File "user.py", line 25, in solution res = max_counter(max_val, N) TypeError: 'int' object is not callable
def increase(x, array, max_value):
current_val = array[x-1]
#if current_val < max_value:
# array[x-1] = max_value
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
lenA = len(A)
n1 = N+1
for z in xrange(lenA):
if A[z] != n1:
res, max_val = increase(A[z], res, max_val)
else:
res = max_counter(max_val, N)
return res
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
lenA = len(A)
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
res = max_counter(max_val, N)
return res
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
lenA = len(A)
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
res = max_counter(max_val, N)
return res
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
max_val = max_val+1
return res
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
max_val = max_val+1
print max_val
return res
4
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
last_update = max_val
print max_val
return res
4
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
last_update = max_val
print max_val
print last_update
return res
4 2
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] +=last_update
return res
def increase(x, array, max_value):
val = array[x-1] +1
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val)
else:
last_update = max_val
print res
for i in xrange(len(res)):
if res[i] < last_update:
res[i] +=last_update
return res
[1, 0, 1, 4, 0]
function result: [3, 2, 3, 4, 2]
[1, 0, 1, 4, 0]
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
last_update = max_val
print res
for i in xrange(len(res)):
if res[i] < last_update:
res[i] =last_update
return res
[2, 0, 1, 4, 0]
function result: [2, 2, 2, 4, 2]
[2, 0, 1, 4, 0]
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
last_update = max_val
print res
for i in xrange(len(res)):
if res[i] < last_update:
res[i] =last_update
return res
WARNING: producing output may seriously slow down your code! [3, 0, 1, 4, 0]
function result: [3, 2, 2, 4, 2]
[3, 0, 1, 4, 0]
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] =last_update
return res
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
last_update +=1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value, last_update
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val, last_update = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value, last_update
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val, last_update = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value, last_update
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val, last_update = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value, last_update
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val, last_update = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value, last_update
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val, last_update = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [3, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [3, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
0 2
function result: [3, 3, 3, 3, 3]
0 2 2 3
function result: [2, 2, 2, 4, 2]
0 2
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
WARNING: producing output may seriously slow down your code! 0 2
function result: [3, 3, 3, 3, 3]
0 2 2 3
function result: [3, 2, 2, 4, 2]
0 2
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update+1:
array[x-1] = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
WARNING: producing output may seriously slow down your code! 0 2
function result: [3, 3, 3, 3, 3]
0 2 2 3
function result: [3, 2, 2, 4, 2]
0 2
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update+1:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
WARNING: producing output may seriously slow down your code! 0 2
function result: [3, 3, 3, 3, 3]
0 2 2 3
function result: [3, 2, 2, 4, 2]
0 2
def increase(x, array, max_value, last_update):
val = array[x-1] +1
if val < last_update+1:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print max_val
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
WARNING: producing output may seriously slow down your code! 2 0 2
function result: [3, 3, 3, 3, 3]
2 0 2 3 2 3
function result: [3, 2, 2, 4, 2]
2 0 2
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1] +1
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print max_val
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
4 0 4
function result: [6, 6, 6, 6, 6]
4 0 4 6 4 6
function result: [5, 4, 4, 8, 4]
4 0 4
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def max_counter(max_value, N):
return [max_value]*N
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for z in A:
if z != n1:
res, max_val = increase(z, res, max_val, last_update)
else:
print max_val
print last_update
last_update = max_val
print last_update
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
WARNING: producing output may seriously slow down your code! 2 0 2
function result: [3, 3, 3, 3, 3]
2 0 2 3 2 3
function result: [3, 2, 2, 4, 2]
2 0 2
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
val = res[i-1]+=1
if val > max_val:
max_val = val
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
File "user.py", line 21 val = res[i-1]+=1 ^ SyntaxError: invalid syntax
File "user.py", line 21 val = res[i-1]+=1 ^ SyntaxError: invalid syntax
File "user.py", line 21 val = res[i-1]+=1 ^ SyntaxError: invalid syntax
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
res[i-1]+=1
val = res[i-1]
if val > max_val:
max_val = val
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [2, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
res[i-1]+=1
val = res[i-1]
if val > max_val:
max_val = val
if val < last_update:
res[i-1] +=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [2, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
res[i-1]+=1
val = res[i-1]
if val > max_val:
max_val = val
if val < last_update:
res[i-1] +=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [2, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
res[i-1]+=1
val = res[i-1]
if val > max_val:
max_val = val
print val
print last_update
if val < last_update:
res[i-1] +=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
1 0 1 0 2 0 1 2 3 2 4 2
function result: [3, 3, 3, 3, 3]
1 0 1 0 2 0 1 2 3 2
function result: [2, 2, 2, 4, 2]
1 0 1 0 2 0 1 2 3 2 4 2
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
res[i-1]+=1
val = res[i-1]
if val > max_val:
max_val = val
print val
print last_update
if val <= last_update:
res[i-1] +=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
1 0 1 0 2 0 1 2 3 2 4 2
function result: [3, 3, 3, 3, 3]
1 0 1 0 2 0 1 2 3 2
function result: [2, 2, 2, 4, 2]
1 0 1 0 2 0 1 2 3 2 4 2
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
res[i-1]+=1
val = res[i-1]
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] +=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [2, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] = last_update
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [3, 3, 3, 3, 3]
function result: [3, 2, 2, 4, 2]
def increase(x, array, max_value, last_update):
array[x-1] +=1
val = array[x-1]
if val < last_update:
array[x-1] = last_update+1
val = last_update+1
else:
array[x-1] = val
if max_value < val:
max_value = val
return array, max_value
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] = last_update
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] = last_update
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [0, 0, 0, 0, 0]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] = last_update
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [1, 1, 1, 1, 1]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i != n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] = last_update
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val <= last_update:
res[i-1] = last_update+1
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [4, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val < last_update:
res[i-1] = last_update+1
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [4, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
val = res[i-1]+1
if val > max_val:
max_val = val
if val < last_update:
res[i-1] = last_update
res[i-1]+=1
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
val = res[i-1]+1
if val < last_update:
res[i-1] = last_update
res[i-1]+=1
if res[i-1] > max_val:
max_val = res[i-1]
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
if res[i-1] < last_update:
res[i-1] = last_update
res[i-1]+=1
if res[i-1] > max_val:
max_val = res[i-1]
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
if res[i-1] < last_update:
res[i-1] = last_update
res[i-1]+=1
if res[i-1] > max_val:
max_val = res[i-1]
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
function result: [2, 2, 2, 2, 2]
function result: [4, 4, 4, 4, 4]
function result: [3, 2, 2, 4, 2]
def solution(N, A):
res = [0] * N
max_val = 0
last_update = 0
n1 = N+1
for i in A:
if i < n1:
if res[i-1] < last_update:
res[i-1] = last_update
res[i-1]+=1
if res[i-1] > max_val:
max_val = res[i-1]
else:
last_update = max_val
for i in xrange(len(res)):
if res[i] < last_update:
res[i] = last_update
return res
The solution obtained perfect score.