A logging system records opening and closing markers for nested operations, but due to a transmission error, some characters in the log were corrupted and replaced with a wildcard symbol.
You are given a string
Determine whether there exists some way to resolve every
A single line containing the string KaTeX can only parse string typed expression.
Print KaTeX can only parse string typed expression if some valid resolution exists, otherwise print KaTeX can only parse string typed expression.
Input
(*))OutputYESExplanationResolving the KaTeX can only parse string typed expression as KaTeX can only parse string typed expression gives the string KaTeX can only parse string typed expression, which is validly balanced: the first and fourth characters form a matching pair, and the second and third characters form a matching pair nested inside.
Example 2:
Input
(OutputNOExplanationA single unmatched opening bracket with no wildcards to resolve it can never be balanced.
Example 3:
Input
*OutputYESExplanationA single wildcard can simply be resolved as an empty string, leaving a valid (empty) balanced sequence.