Coders Crushby Napplied AI
Back to DSA Problems
MediumStack & Queue

Min Stack

Stack supporting min queries

Solution Approach

Use Stack for LIFO problems. Useful for matching pairs (parentheses), expression evaluation, or monotonic patterns. Maintain stack of elements and pop when condition met.

Implementation
def isValid(s):
    stack = []
    pairs = {"(": ")", "[": "]", "{": "}"}
    for char in s:
        if char in pairs:
            stack.append(char)
        else:
            if not stack or pairs[stack.pop()] != char:
                return False
    return len(stack) == 0
Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(n)
Key Learning Points
LIFO structureMatch pairs efficientlyUseful for bracket problems
Related Problems to Practice
Valid ParenthesesMin StackDaily Temperatures
Complexity
Time:O(n)
Space:O(n)
Asked at
GoogleAmazonFacebook
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless