• + 0 comments

    It is O(n) because you look at each element at most twice, once while pushing it on the stack (L to R) and once when popping from the stack (for scanning R to L). Once elements are popped off the stack, they're not inspected any more.