You are viewing a single comment's thread. Return to all comments →
Nice one. Some improvements:
Python2 version:
def candies(n, arr): count = [1] for i,x in enumerate(arr[1:],1): if x <= arr[i-1]: count.append(1) else: count.append(count[i-1]+1) for i,x in enumerate(arr[-2::-1],2): if x <= arr[n-i+1]: count[n-i] = max(count[n-i], 1) else: count[n-i] = max(count[n-i], count[n-i+1]+1) return sum(count)
Candies
You are viewing a single comment's thread. Return to all comments →
Nice one. Some improvements:
Python2 version: