code.davidloor.com
EEasy· stack· string

Valid Parentheses

Valid Parentheses

Given a string s containing only the characters (, ), {, }, [, and ], determine if the string is valid. A string is valid if every open bracket is closed by the same type of bracket, and brackets are closed in the correct order. An empty string is considered valid.

Example

Input: s = "()[]{}" → Output: true Input: s = "(]" → Output: false Input: s = "([)]" → Output: false Input: s = "{[]}" → Output: true

Constraints

  • 1 ≤ s.length ≤ 10⁴
  • s consists of parentheses characters only: ()[]{}.

Entry — isValid

Grading — exact over 5 tests

Stuck? Browse algorithmic patterns → or read the Python / JS foundations.
Awaiting first run
Reference solution unlocks after a run & 60 s of work.