Coders Crushby Napplied AI
Back to DSA Problems
EasyStack & Queue

Valid Parentheses

Check if parentheses are valid

Solution Approach

Use stack to match opening and closing brackets. Check each closing matches top of stack.

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