102. validate string of parentheses

JavaScriptAlgorithm
Is this helpful ?

easy  - accepted / - tried

Given a string containing only following characters:

  1. parentheses : ( or )
  2. brackets: [ or ]
  3. braces: { or }

write a function to determine if they are valid.

By 'valid', it means all should be rightly paired, and with the valid order.


validate('{}[]()') 
// true

validate('{[()]}') 
// true

validate('{[}]') 
// false, they are not in the right order

validate('{}}') 
// false, last `}` is not paired with `{`

Follow-up

What is time & space complexity of your approach ? Can you do it better?

Let's try to solve this problem within 10 minutes.

Discuss(45)