Unexpected answer

Whats the expected output for [1, 2, 2, 2]?

Expected answer: 5
Answer according to me: 7 (1+2+2+2)

It should be 1+2+1+1 .
As, “children with a higher rating get more candies than their neighbors”
2 at index 1 gets higher rating than 1 at index 0, However, 2 at index 2 and 3 has same rating as their neighbors.

Click here to start solving coding interview questions