Created
June 19, 2016 14:29
-
-
Save maksverver/e5486785ab2abd4a8adf9d6b0822936b to your computer and use it in GitHub Desktop.
Candies
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
# https://www.hackerrank.com/challenges/candies | |
import sys | |
N = int(sys.stdin.readline()) | |
ratings = [ int(sys.stdin.readline()) for n in range(N) ] | |
candies = [1]*N | |
for i in range(1, N): | |
if ratings[i] > ratings[i - 1]: | |
candies[i] = candies[i - 1] + 1 | |
for i in reversed(range(N - 1)): | |
if ratings[i] > ratings[i + 1]: | |
candies[i] = max(candies[i], candies[i + 1] + 1) | |
print sum(candies) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment