Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
Given a string P
containing just the characters (
, )
, {
, }
, [
and ]
, determine if the string P
is valid.
An input string P
is valid if:
Example 1:
Input: P = "()"
Output: True
Example 2:
Input: P = "()[]{}"
Output: True
Example 3:
Input: P = "(]"
Output: False
Example 4:
Input: P = "([)]"
Output: False
Example 5:
Input: P = "{[]}"
Output: True
Constraints:
len(P)
<= 104P
consists of parentheses only ()[]{}
.validate_parentheses
P
Complete the below code in the right side coding panel
def validate_parentheses(P: str) -> bool:
# your code goes here
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...