Problem :

https://www.hackerrank.com/challenges/candies/problem


My Solution :

#!/usr/bin/env python3

def candies(n, arr):
    c = [1]*n
    for i in range(n-1):
        if arr[i] < arr[i+1]:
            c[i+1] = c[i] + 1
    for j in range(n-1, 0, -1):
        if arr[j] < arr[j-1] and c[j] >= c[j-1]:
            c[j-1] = c[j] + 1
    return sum(c)


n = int(input())
arr = []
for _ in range(n):
    arr_item = int(input())
    arr.append(arr_item)
result = candies(n, arr)
print(result)