DIY: Valid Parentheses

Solve the interview question "Valid Parentheses" in this lesson.

Problem statement

For this problem, you are given a string, s, that may be empty or may consist of opening and closing parentheses. Your task is to check that the string contains valid parenthesization or not.

Constraints

  • 1 <= s.length <= 10410^4
  • The s will only contain parentheses (), square brackets [], and braces {}.

Input

The function will take a string, s. Here is an example of the input:

s = "(){[{()}]}"

Output

The function will return true if s contains a properly matched sequence of brackets. Otherwise, it will return false. The following is the output of the input given above:

true

Coding exercise

For this coding exercise, you need to implement the isValid(s) function, wherein the s will either be empty or a set of parentheses.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.