597. Balanced Brackets with Wildcard

EasyStackStackGreedyString

Given a string s containing '(', ')', and '*', where each '*' may be treated as '(', ')', or an empty string, determine whether s can be made a valid balanced parentheses string. Return true or false. The input is JSON {s}.

Input: JSON {s}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"s":"(*))"}
Output: true
Explanation: The '*' can be empty.
Example 2
Input: {"s":"(*)"}
Output: true
Explanation: The '*' can be empty.
Example 3
Input: {"s":"(("}
Output: false
Explanation: Two unmatched opens.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →