Python two pass solution (left to right, then right to left).
    \n    def candy(self, ratings):\n        res = len(ratings) * [1]\n        for i in xrange(1, len(ratings)):  # from left to right\n            if ratings[i
        \n    def candy(self, ratings):\n        res = len(ratings) * [1]\n        for i in xrange(1, len(ratings)):  # from left to right\n            if ratings[i] > ratings[i-1]:\n                res[i] = res[i-1] + 1\n        for i in xrange(len(ratings)-1, 0, -1):  # from right to left\n            if ratings[i-1] > ratings[i]:\n                res[i-1] = max(res[i-1], res[i]+1)\n        return sum(res)
['Python']