This code visualizes the solution to this Twitter interview question.
My first solution only looked at immediate neighbors to figure out if you're in a trough that will collection water. The clever part is considering all values to the left and right of you, not immediate neighbors. My naive solution to
[5,1,5] was pretty close, but as I expanded to more complex problems, considering your neighbors wasn't enough and my solution began to bloat. Looking at this answer gave me the insight to strip down my solution.
Once I had it solved I went back and built the simple solution display.
To run the tests simply run
$> ruby -Itest rain_test.rb