Candy (LeetCode 135)
Asked in the DSA round stage.
Given an array ratings, assign at least one candy to each child. For every pair of adjacent children, a child with a higher rating must receive more candies than that neighbor. Return the minimum total number of candies required.
Input: ratings, a list of integers. Output: an integer.
Examples: [1, 0, 2] returns 5; [1, 2, 2] returns 4 because equal ratings impose no requirement.
Constraints: 1 <= len(ratings) <= 1000; 0 <= ratings[i] <= 10^5.
def candy(ratings):