Facebook PixelValid Parentheses — Coding Practice
Valid ParenthesesEasy

Valid Parentheses

Easy 23.8k41% acceptance
StringStack

Given a string s containing just the characters (), [] and {}, determine if the input is valid.

A string is valid when every opening bracket is closed by the same type of bracket, in the correct order, and every closing bracket has a matching opener.

Example 1
Input: s = "()[]{}"
Output: true
Example 2
Input: s = "(]"
Output: false
Example 3
Input: s = "([)]"
Output: false
Closed in the wrong order.
Constraints
  • 1 ≤ s.length ≤ 10⁴
  • s consists only of the characters ()[]{}.
Asked atAmazonMicrosoftGoogleBloomberg
JavaScript
Loading editor…
Case 1
"()"
expected: true
Case 2
"()[]{}"
expected: true
Case 3
"(]"
expected: false
Case 4
"([)]"
expected: false
Case 5
"{[]}"
expected: true
Case 6
"("
expected: false