โ† Core Algorithms
#2 most askedVery commonEasyStack

Valid Parentheses

New to Stack? Learn it from scratch first
Two Pointers & Stacks โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Given a string of brackets ()[]{}, return True if every opening bracket is closed by the same type, in the right order.

"([]{})" โ†’ True, "(]" โ†’ False, "((" โ†’ False.

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def is_valid(s):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.