Maximal Rectangle (algorithm from leetcode discuss)