Python3 100% Time Efficient Soln. O(n) time O(1) space
class Solution:\n    def candy(self, ratings: List[int]) -> int:\n        \n        \n        up = 1\n        down = 0\n        rat = 1\n        peak = 0\n     
class Solution:\n    def candy(self, ratings: List[int]) -> int:\n        \n        \n        up = 1\n        down = 0\n        rat = 1\n        peak = 0\n        \n        for i in range(1,len(ratings)):\n            \n            if ratings[i]>ratings[i-1]:\n                up+=1\n                down =  0\n                rat+=up\n                peak = up\n                \n            elif ratings[i]==ratings[i-1]:\n                down = 0\n                peak = 0\n                up = 1\n                rat+=1\n                \n            else:\n                down+=1\n                up = 1\n                rat+=down\n                if peak<=down:\n                    rat+=1\n                    \n        return rat
['Array', 'Python', 'Python3']