Tag view

#stack

Cross-subject tag search for related interview cards.

Clear

Results update as you type. Press / to jump straight into search.

Tagged with stack

3 cards

Coding Exercises Medium O(1)

Min Stack

Push each value onto the main stack and also onto a min stack whenever it is less than or equal to the current minimum. When popping, remove it from the min stack too if it matches the current minimum.

Implement a stack that supports push, pop, top, and get_min in constant time.

Coding Exercises Medium O(n)

Next Greater Element

Walk the array from right to left and maintain a stack of candidates greater than the current value. Pop smaller values because they can never be the next greater element for earlier entries.

For each element in an array, return the next greater element to its right, or -1 if none exists.

Coding Exercises Easy O(n)

Valid Parentheses

Push opening brackets onto a stack and pop when you see a matching closer. Any mismatch or leftover opening bracket means the string is invalid.

Check whether brackets in a string are balanced and properly nested.