Constant memory solution for the trapped water problem.