Skip to content

Instantly share code, notes, and snippets.

@markroxor
Created September 19, 2015 14:23
Show Gist options
  • Save markroxor/38fcb56e1d06fb3a6292 to your computer and use it in GitHub Desktop.
Save markroxor/38fcb56e1d06fb3a6292 to your computer and use it in GitHub Desktop.
HackerRank DP Practise Candies
from sys import stdin
nex = iter(map(int,stdin.read().split())).next
n = nex()
list = []
lt = []
rt = []
for i in xrange(n):
list.append(nex())
lt.append(1)
rt.append(1)
for i in xrange(1,n):
if(list[i]>list[i-1]):
lt[i] = lt[i-1] + 1
for i in xrange(n-2,-1,-1):
if(list[i]>list[i+1]):
rt[i] = rt[i+1] + 1
for i in xrange(n):
list[i] = max(lt[i],rt[i])
print sum(list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment