Spent way too much time on the Candy problem. I was on the right direction but missed a few tiny points. The Trapping Rain Water problem was solved using a similar trick.