J.P. Morgan interview question

Water level problem leetcode hard