Two passes

  • from left to right

Ensure any child has more candies than the child on his left

  • from right to left

Ensure any child has more candies than the child on his right