a solution similar to maximal rectangle in histogram