DIY: Valid Parentheses
Solve the interview question "Valid Parentheses" in this lesson.
We'll cover the following
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.
Constraints
- 1 <=
string.length
<= - The
string
will only contain parentheses()
, square brackets[]
, and braces{}
.
Input
The function will take a string
. Here is an example of the input:
input = "(){[{()}]}"
Output
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:
True
Coding exercise
For this coding exercise, you need to implement the is_valid(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.