Stack

Binary Tree Inorder Traversal

Traverse a binary tree in inorder (left -> root -> right)

Binary Tree Preorder Traversal

Traverse a binary tree in preorder (root -> left -> right)

Flatten Multilevel Linked List

Flatten a multilevel doubly linked list into a single level

Implement Queue using Stacks

Implement a queue using two stacks with O(1) amortized time complexity for all operations.

Implement Stack

Design and implement a stack data structure with push, pop, top, and empty operations

Implement Stack using Queues

Implement a stack using two queues with O(1) amortized time complexity for all operations.

Largest Rectangle in Histogram

Find the largest rectangle that can be formed in a histogram

Max Stack

Design a stack that supports push, pop, top, peekMax, and popMax operations

Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time

Minimum Insertions to Balance Parentheses

Find minimum insertions needed to balance parentheses string

Next Greater Element

Find the next greater element for each element in an array.

Postorder Traversal

Traverse binary tree in postorder (left, right, root)

Remove K Digits

Remove k digits from a number to make it as small as possible

Stock Span Problem

Calculate the span of stock prices for each day

Trapping Rain Water

Calculate how much rainwater can be trapped between bars of different heights

Valid Parentheses

Determine if the input string has valid brackets that are properly opened and closed

Valid Parentheses

Check if a string containing only parentheses is valid.