Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.4
- def solution(N, A):
- # write your code in Python 2.7
- last_max_operation = -1
- for i in range(len(A) - 1, -1, -1):
- if A[i] == N + 1:
- last_max_operation = i
- break
- counters = [0] * N
- if last_max_operation == -1:
- for a in A:
- counters[a - 1] += 1
- return counters
- max_val = 0
- base = 0
- for i in range(last_max_operation):
- if A[i] == N + 1:
- base = max_val
- else:
- diff = max(base - counters[A[i] - 1], 0)
- counters[A[i] - 1] += (1 + diff)
- if counters[A[i] - 1] > max_val:
- max_val = counters[A[i] - 1]
- final_counters = [max_val] * N
- if last_max_operation < len(A) - 1:
- for a in A[last_max_operation + 1:]:
- final_counters[a - 1] += 1
- return final_counters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement