Approach hintTry it first, then revealHide
Make two passes. Left to right, give a child one more candy than its left neighbour when its rating is higher; right to left, raise a count that is not above a lower-rated right neighbour. Sum the results.
Make two passes. Left to right, give a child one more candy than its left neighbour when its rating is higher; right to left, raise a count that is not above a lower-rated right neighbour. Sum the results.