I have the following problem:
You are given N counters, initially set to 0, and you have two possible operations on them:
def solution(N, A): res = [0] * N maxV, minV = 0, 0 for x in A: if 1 <= x <= N: res[x-1] = max(res[x-1], minV) + 1 maxV = max(maxV, res[x-1]) else: minV = maxV for i in range(N): res[i] = max(res[i], minV) return res