Solution using multi source bfs (idk why)
Approach: \n1) Start with the positions that are smaller than both their neighbors and add this to a set.\n2) Then loop until this set has elements and for each
Approach: \n1) Start with the positions that are smaller than both their neighbors and add this to a set.\n2) Then loop until this set has elements and for each iteration add the neighbor for the positions in the set that have a higher rating. At each iteration the number of candies for a position increments by 1 (shown in code by variable curr). \n```\nclass Solution(object):\n    def candy(self, ratings):\n        """\n        :type ratings: List[int]\n        :rtype: int\n        """\n        n = len(ratings)\n        if n == 1:\n            return 1\n        \n\t\t#stores the elements that are smaller than both its neighbors\n        s = set()\n        \n        if ratings[0] <= ratings[1]:\n            s.add(0) # first position\n            \n        if ratings[n-1] <= ratings[n-2]:\n            s.add(n-1) # last position \n        \n        for i in range(1, n-1):\n            if ratings[i] <= ratings[i-1] and ratings[i] <= ratings[i+1]:\n                s.add(i) # everything in between\n  \n        curr = 0\n        count = [1] * n # start with everyone having one candy\n        \n        while s:\n            curr += 1\n            ns = set()\n            \n            for i in s:\n                count[i] = curr\n                if i != 0 and ratings[i-1] > ratings[i]:\n                    ns.add(i-1) # add left neighbor if it is greater\n                if i != n-1 and ratings[i+1] > ratings[i]:\n                    ns.add(i+1) # add right neighbor if it is greater\n            s = ns\n            \n        return sum(count)```
['Breadth-First Search', 'Python']