We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defcandies(n,arr):ifn==0:return0candies=[1]*n# Left to right passforiinrange(1,n):ifarr[i]>arr[i-1]:candies[i]=candies[i-1]+1# Right to left passforiinrange(n-2,-1,-1):ifarr[i]>arr[i+1]:candies[i]=max(candies[i],candies[i+1]+1)returnsum(candies)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Candies
You are viewing a single comment's thread. Return to all comments →