Question bankPricingSign in

Valid Parentheses

Stacks & QueuesEasy1:00

Given a string containing only the characters '(', ')', '{', '}', '[' and ']', explain how you would determine if the input string has valid (properly matched and nested) parentheses.

For example: - "()" is valid - "()[]{}" is valid - "(]" is invalid - "([)]" is invalid - "{[]}" is valid

How does your approach handle nested brackets? What edge cases should you consider?

Explain your approach and analyze the time and space complexity.

How to approach it

  • Hint 1

    Think about which data structure naturally handles a last-in, first-out matching pattern.

  • Hint 2

    Push opening brackets onto a stack. When you encounter a closing bracket, check if it matches the top of the stack.

  • Hint 3

    Don't forget edge cases: an empty string is valid, a string with only opening brackets is invalid, and a closing bracket with an empty stack is invalid.

Ready to answer it out loud?

Record your answer in 1:00 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.