Valid Parenthesis String
A medium-tier problem at 39% community acceptance, tagged with String, Dynamic Programming, Stack. Reported in interviews at Alibaba and 6 others.
Valid Parenthesis String is a medium-difficulty string problem asking you to validate parentheses with wildcards. It's been asked at Alibaba, TikTok, LinkedIn, Roku, Blizzard, ServiceNow, and Tekion. The acceptance rate sits at 39%, which tells you most candidates miss the trick on first attempt. The gotcha: asterisks can act as open parens, close parens, or nothing at all, so brute force recursion times out. You need to either track a range of possible open-paren counts (greedy) or rebuild the string state systematically (DP). If this hits your live assessment and you blank on the state-space approach, StealthCoder solves it in seconds invisible to the proctor.
Companies that ask "Valid Parenthesis String"
Valid Parenthesis String is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe problem forces you to track uncertainty. A naive approach tries all possibilities for each wildcard, which explodes exponentially. The winning insight is greedy: traverse left to right, keeping track of the minimum and maximum possible count of unmatched open parentheses. When you see '(', both bounds go up. When you see ')', both bounds go down. When you see '*', min can stay the same or go down, max goes up. Prune impossible states (max < 0 means too many closes). If min ever goes negative, bump it to zero. At the end, min must be exactly zero. This avoids exponential branching. A DP approach works too, but greedy is faster. Common trap: forgetting to handle min == -1 or letting it drop below zero. StealthCoder is the fallback when the greedy logic doesn't click during the timer.
Pattern tags
You know the problem.
Make sure you actually pass it.
Valid Parenthesis String recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Valid Parenthesis String interview FAQ
Is this problem really asked at top companies?+
Yes. Alibaba, TikTok, LinkedIn, Roku, Blizzard, ServiceNow, and Tekion have all reported it. The 39% acceptance rate shows it filters candidates well, so expect it if you're interviewing at those firms.
What makes this harder than regular parenthesis matching?+
Wildcards create ambiguity. Each '*' can be '(', ')', or ignored. That multiplies into exponential branches if you simulate naively. The trick is tracking a range of valid open counts instead of simulating each path.
Will dynamic programming or greedy be faster?+
Greedy is faster and uses O(1) space versus O(n) for DP. Both pass, but greedy with min/max bounds is the intended solution. It's also easier to code correctly under timer pressure.
What's the most common mistake candidates make?+
Letting min drop below zero or not resetting it to zero when it goes negative. Also forgetting to check that min is exactly zero at the end, not just non-negative. The edge case is strings like '***' or '(*)'.
Do I need to know all four topics listed?+
No. String and Greedy cover the optimal solution. Stack and DP are alternate approaches. Greedy is the path interviewers expect. Knowing stack helps you explain the intuition, but it's not required to solve it.
Want the actual problem statement? View "Valid Parenthesis String" on LeetCode →