Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Valid Parentheses

Easy
stringstack

Given a string s containing only the characters ()[]{}, determine if it is valid: brackets must close in the correct order and every opening bracket has a matching closing bracket of the same type.

Input: one line s. Output: true or false.

Example 1
Input:
()[]{}
Output:
true
Example 2
Input:
(]
Output:
false

Constraints

  • 1 ≤ s.length ≤ 10^4
  • s consists only of the characters ()[]{}.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.