LC 42 - Trapping Rain Water
Approach I was orginally thinking that we can colelct all the peaks, and fill the water between peaks, but finding that this might not be correct. For example like [2,0,1,0,1,0,2], if we fill between peaks, the 3-rd (0-indexed) would be 1, but it is actaully 2. Later I come up with the idea for using mono stack. We collect all the points in increasing order, and try to fill from one to another. We also do the same thing backwards, since the mono-stack would stop on the largest element. ...