DIY: Valid Parentheses

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

Problem statement

For this problem, you are given a string 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.


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


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

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


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


Coding exercise

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

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