Facebook Pixel

Valid Parentheses

For this question we ask you to determine whether or not a string has valid parentheses. A string has valid parentheses if each bracket is closed and opened in the same order and has the same type. Parentheses has 3 types (), {} and []

Input & Output
Input
s — String containing the parentheses
Output
Whether or not the string is valid
Example
Input
s = ()
Output
true
Explanation

This is a valid parentheses sequence.

Example
Input
s = (}
Output
false
Explanation

This is not valid as } cannot match (.

Constraints
  • 1 <= s.length <= 100000

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro