leetcode Candy  O(n) vs. O(n^2)