Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Solution: Valid Parentheses

Problem Statement

Determine if an input string containing only the characters '(', ')', '{', '}', '[', and ']' is valid. A string is considered valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.
  3. Each close bracket has a corresponding open bracket of the same type.


    • Input: "(]"
    • Expected Output: false
    • Justification: The opening parenthesis '(' is not closed by its corresponding closing parenthesis.
    • Input: "{[]}"
    • Expected Output: true




Like the course? Get enrolled and start learning!