# Tag: Stack

Min Stack. Basically, the trick is to use another stack to keep track of all the push-in min number, so that whenever a current min number is popped, the next…

Evaluate Reverse Polish Notation. This is a typical stack problem. Whenever there is a number, push it to the stack, whenever there is a operator, push two number from the…

Valid Parentheses. Classic stack problem. When you encounter a left parentheses, push it to a stack. When you encounter a right parentheses, pop the stack. If the pop left parentheses…

Maximal Rectangle. This problem is an extended version of Largest Rectangle in Histogram. We just need to calculate the heights in each row and find the largest rectangle in those heights.

Largest Rectangle in Histogram. I tried to solve this problem by using an O(n2) solution (Loop through all heights, count the number of heights continually larger than the current height…