HARDasked at 5 companies

Remove Invalid Parentheses

A hard-tier problem at 49% community acceptance, tagged with String, Backtracking, Breadth-First Search. Reported in interviews at Deliveroo and 4 others.

Founder's read

Remove Invalid Parentheses is a hard string problem that shows up at Meta, Google, Deliveroo, and other companies. You're given a string with parentheses and letters, and you need to remove the minimum number of invalid parentheses to make it valid. The trap is thinking you can solve it greedily or in a single pass. You can't. Most candidates either overcomplicate the state space or miss that you need to explore multiple removal paths at once. With nearly 50% acceptance, this is a screen-share problem where panic sets in fast. If you freeze on the pattern, StealthCoder runs invisible during your assessment and gives you a working solution in seconds.

Companies asking
5
Difficulty
HARD
Acceptance
49%

Companies that ask "Remove Invalid Parentheses"

If this hits your live OA

Remove Invalid Parentheses 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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The key insight is that you can't know which parenthesis to remove without trying multiple options. Breadth-first search is the most reliable approach: start with the original string, and at each level remove one character at a time, building new candidate strings. When you find valid strings, track the removal count and stop exploring paths that exceed that minimum. Backtracking works too, but BFS is cleaner because it naturally gives you the shortest removal sequence. The gotcha is that efficiency matters. A naive brute force will time out. You need to prune aggressively: skip duplicate strings, skip branches that have already removed more characters than your best solution, and cache which strings you've already seen. String validation (checking if parentheses are balanced) is a helper you'll call often, so make it tight. StealthCoder is the safety net if you blank on the BFS structure or get caught optimizing the pruning logic mid-interview.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Remove Invalid Parentheses recycles across companies for a reason. It's hard-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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Remove Invalid Parentheses interview FAQ

Is greedy or single-pass removal enough?+

No. You can't determine the optimal removal in one pass because removing one parenthesis changes which others are invalid. BFS forces you to try all minimal removal paths in parallel. That's why the problem is hard and why greedy candidates fail.

How do you avoid timeout on large inputs?+

Cache seen strings in a set so you don't revisit the same candidate. Prune branches that exceed the current minimum removal count. Stop exploring once you've found valid strings at a certain removal depth. BFS naturally limits redundant work.

Does this actually appear at Google and Meta?+

Yes, it's in the reported ask history for both companies, plus Deliveroo, Snowflake, and Rubrik. It's not a common warm-up. If you see it, they're testing your ability to recognize when greedy fails and pivot to graph/state-space search.

How does backtracking relate to BFS here?+

Both explore the state space, but backtracking is depth-first and requires you to track the removal count carefully to prune. BFS is breadth-first and naturally finds the shortest removal sequence because you stop at the first valid level. BFS is usually cleaner for this problem.

What's the trick to validating parentheses quickly?+

Use a counter: increment for open parentheses, decrement for close. If the counter goes negative, it's invalid. If it's non-zero at the end, invalid. Do this check on every candidate string during BFS. It's O(n) per check and you can't skip it.

Want the actual problem statement? View "Remove Invalid Parentheses" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.