Skip to content

Instantly share code, notes, and snippets.

@gbazilio
Created January 22, 2017 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbazilio/7ee7cb6a2b42ef3528780777adc323e5 to your computer and use it in GitHub Desktop.
Save gbazilio/7ee7cb6a2b42ef3528780777adc323e5 to your computer and use it in GitHub Desktop.
Codility - Max Counter
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