Created
January 22, 2017 14:56
-
-
Save gbazilio/7ee7cb6a2b42ef3528780777adc323e5 to your computer and use it in GitHub Desktop.
Codility - Max Counter
This file contains hidden or 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
def solution(N, A): | |
max_counter = last_max_counter = 0 | |
counters = [0] * N | |
for k in xrange(len(A)): | |
current_counter = A[k] | |
if current_counter == N+1: | |
last_max_counter = max_counter | |
else: | |
counters[current_counter - 1] = max(counters[current_counter - 1], last_max_counter) + 1 | |
max_counter = max(max_counter, counters[current_counter - 1]) | |
for i in xrange(N): | |
counters[i] = max(counters[i], last_max_counter) | |
return counters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment