Generate Parentheses
A medium-tier problem at 77% community acceptance, tagged with String, Dynamic Programming, Backtracking. Reported in interviews at Texas Instruments and 39 others.
Generate Parentheses shows up in 40+ company assessments, including Amazon, Disney, and ServiceNow. You're asked to produce all valid combinations of n pairs of balanced parentheses. The obvious brute-force approach (generate everything, filter valid ones) times out. The trick is understanding that you can only add a closing paren when you have unmatched opens, and only add an opening paren when you haven't hit the limit. Most candidates blank on this constraint or write backtracking that explores dead branches. If this problem hits your live OA and the recursion logic doesn't click, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Generate Parentheses"
Generate 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. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe core pattern is constrained backtracking. You maintain two counters: opens placed so far and closes placed so far. At each step, you can add an open paren if opens < n, and a close paren only if closes < opens. This guarantees valid strings and eliminates filtering. The space complexity is the depth of the recursion tree, and the time complexity is proportional to the number of valid sequences (Catalan number). Most candidates either try to generate then validate (wasteful) or recurse without the closes < opens guard (produces invalid strings). Dynamic Programming approaches exist but backtracking is cleaner for interviews. The acceptance rate sits at 77 percent, suggesting it's harder than it looks once you're live and the syntax requires focus.
Pattern tags
You know the problem.
Make sure you actually pass it.
Generate Parentheses 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 by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Generate Parentheses interview FAQ
Is this really asked at big tech companies?+
Yes. Amazon, Disney, ServiceNow, and Walmart Labs all report asking it. It's a medium-difficulty classic, so expect it in phone screens and first-round online assessments across 40+ organizations. It's not a rarity.
Why does brute force fail?+
Generating all 2^(2n) strings and filtering is exponential in practice. The backtracking approach prunes the tree by only exploring valid paths (the Catalan number of sequences), reducing wasted branches significantly. That's why it passes.
What's the key constraint I always forget?+
You can only add a closing paren when the number of closes placed is strictly less than the number of opens placed. Without this guard, you generate invalid strings. Nail this in your mental model before coding.
Is this a backtracking or DP problem?+
Both approaches work. Backtracking is the standard live-interview solution because it's intuitive: recurse left with an open, recurse right with a close when valid. DP is overkill here and slower to code under pressure.
How do I know if I got it right?+
For n=2, you should get four strings: '(())', '()()'. For n=3, you should get five strings. Count your results against the Catalan number for n. If your count matches, your logic is sound.
Want the actual problem statement? View "Generate Parentheses" on LeetCode →