Sweets by rating

Children stand in a line with ratings. Each child gets at least one sweet, and any child with a higher rating than a neighbour must get more sweets than that neighbour. Write min_sweets(ratings) that returns the fewest sweets in total.

min_sweets([1, 0, 2])  ->  5     (2, 1, 2)
min_sweets([1, 2, 2])  ->  4     (1, 2, 1)
min_sweets([5])        ->  1

The point is to practise a two-pass greedy: satisfy the left neighbours going right, then the right neighbours going left, taking the max.

def min_sweets(ratings):
    ...