N children are standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to the following requirements:
What is the minimum number of candies you must give?
1 <= N <= 105
-109 <= A[i] <= 109
The first and only argument is an integer array A representing the rating of children.
Return an integer representing the minimum candies to be given.
A = [1, 2]
A = [1, 5, 2, 1]
The candidate with 1 rating gets 1 candy and candidate with rating 2 cannot get 1 candy as 1 is its neighbor. So rating 2 candidate gets 2 candies. In total, 2 + 1 = 3 candies need to be given out.
Candies given = [1, 3, 2, 1]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.