PIXELBANKv9.1.0
Menu

Valid Parenthesis String

Given a string with (, ), and *****, where ***** can be (, ), or empty, return True if the string is valid.

Example:

Input:
(*)
Output:
True
Reasoning:
  • The input string is (*), containing one * which can be treated as an empty string, an open parenthesis (, or a close parenthesis ).
  • Considering the * as an empty string, the string becomes `` (empty string), which is a valid parenthesis string since it doesn't contain any unmatched parentheses.
  • Alternatively, the * can also be treated as a ( or a ), resulting in strings ( or ), but since there's no matching counterpart, these cases would not be valid on their own.
  • However, because the * can be considered as an empty string, the overall string (*) is considered valid, leading to the output True.

Constraints:

  • 1 <= len(s) <= 100
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Valid Parenthesis String - Medium | PixelBank