Back to course home
0% completed
Vote For New Content
Valid Parentheses (easy)
Problem Statement
Determine if an input string containing only the characters '(', ')', '{', '}', '[', and ']' is valid. A string is considered valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
- Each close bracket has a corresponding open bracket of the same type.
Examples
-
- Input:
"(]"
- Expected Output:
false
- Justification: The opening parenthesis '(' is not closed by its corresponding closing parenthesis.
- Input:
-
- Input:
"{[]}"
- Expected Output:
true
- Justification: The string contains pairs of opening and closing brackets in the correct order.
- Input:
-
- Input:
"[{]}"
- Expected Output:
false
- Justification: The opening square bracket '[' is closed by a curly brace '}', which is incorrect.
- Input:
Constraints:
- 1 <= s.length <= 10<sup>4</sup>
s
consists of parentheses only '()[]{}'.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible