4 ms·
Your solution doesn't work when there is more than one "puddle": https://gist.github.com/alexchow/7228746 https://gist.github.com/alexchow/7228746 Try the cas
by acchow 13y ago
Your solution doesn't work when there is more than one "puddle":
https://gist.github.com/alexchow/7228746 https://gist.github.com/alexchow/7228746
Try the case: ([2,5,1,2,3,4,7,7,6,3,5], 12)
- igor47 13y agoit's not "more than one puddle"; it's that i don't count the second puddle because i don't ever "close" it by encountering it's level again. if i go off the edge, i should close it as best i can.
- acchow 13y agoAh, right. Now that I actually read your code, that's the real bug :p The issue with this "state machine" approach is you don't have "lookahead". In the two pass approach (approach from one side, then the other), you essentially have two machines, one implicitly serving as the "lookahead" for the other.