Visa Inc. interview question

Rainwater retention problem from leetcode.