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(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.