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):# Write your code heretotal_candy=[1]*nforiinrange(1,n):ifarr[i]>arr[i-1]:total_candy[i]=total_candy[i-1]+1foriinrange(n-2,-1,-1):ifarr[i]>arr[i+1]:total_candy[i]=max(total_candy[i],total_candy[i+1]+1)# The result is the sum of all total_candyreturnsum(total_candy)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Candies
You are viewing a single comment's thread. Return to all comments →
Python solution