Created
September 2, 2015 03:35
-
-
Save 43061b4a/3dab2f5ed75a410257f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def solution(N, A): | |
counters = [0] * N | |
max_counter = 0 | |
all_inc = 0 | |
N1 = N + 1 | |
for i in range(len(A)): | |
if 1 <= A[i] <= N: | |
if counters[A[i] - 1] < all_inc: | |
counters[A[i] - 1] = all_inc | |
counters[A[i] - 1] += 1 | |
if counters[A[i] - 1] > max_counter: | |
max_counter = counters[A[i] - 1] | |
elif A[i] == N1: | |
all_inc = max_counter | |
for j in range(len(counters)): | |
counters[j] = max(counters[j], all_inc) | |
return counters | |
print solution(5, [3, 4, 4, 6, 1, 4, 4]) | |
#https://codility.com/demo/results/demoKHVSJH-8HJ/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment