Created
November 4, 2019 14:37
-
-
Save imedadel/0ddeea6803b0e3c8d7fd1962b13ae6d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def candies(n, arr): | |
if len(arr) == 1: | |
return 1 | |
candies = [1]*len(arr) | |
candies[0] = 1 | |
for i in range(1, len(arr)): | |
if arr[i] > arr[i-1]: | |
candies[i] = candies[i] + candies[i-1] | |
for i in range(len(arr)-2, 0, -1): | |
if arr[i] > arr[i-1] and candies[i] <= candies[i+1]: | |
candies[i] = candies[i+1] + 1 | |
return sum(candies) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment