class Solution: def candy(self , arr: List[int]) -> int: # write code here l = len(arr) if l < 2: return l res = [1] * l # left ---> right for i in range(1, l): if arr[i] > arr[i-1]: res[i] = res[i-1] + 1 # left <--- right for i in range(l-2, -1, -1): if arr[i] > arr[i+1]: res[i] = max(res[i], res[i+1] + 1) return sum(res)