102. validate string of parentheses

JavaScriptAlgorithmstring TikTok

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('{}[]()') // truevalidate('{[()]}') // truevalidate('{[}]') // false, they are not in the right ordervalidate('{}}') // false, last `}` is not paired with `{`

Follow-up

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

Always try to find a better approach.