Candy
Intuition My thought was first going left to right checking both neighbours. For example, for [1,2,3,4] would work perfectly. However it’s not possible to solve this in one pass checking both neighbours. We need to use a two pass approach, LTR, RTL. To visualize better the problem, using [1,2,3,4] let’s see how many candies LTR and RTL would give for each children: LTR [1,2,3,4] -> [1,2,3,4] since it's always increase each children get's one more candy than the previous one. RTL [1,2,3,4] -> [1,1,1,1] From RTL perspective, it's always decreasing, so all children get's one. In this case the correct solution is [1,2,3,4] ...