Hacker News new | ask | show | jobs
by twiceaday 4612 days ago
Here is a novel solution.

  make stack
  water = 0
  for n in columns
    while stack not empty and n > stack top
      water += min(stack bottom, n) - stack top
      pop stack
    stack push n