Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(N, A):
# write your code in Python 2.7
rmin = 0
rmax = 0
C = [0] * N
M = len(A)
if not M:
return C
for i in range(M):
X = A[i]
if X <= N:
X = X - 1
c = C[X]
if c < rmin:
c = rmin + 1
else:
c = c + 1
rmax = max(rmax, c)
C[X] = c
elif X == N+1:
rmin = rmax
for i in range(N):
if C[i] < rmin:
C[i] = rmin
return C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.