As reported: Walmart SE-III DSA round (May 2025), second question: LeetCode 22 Generate Parentheses. It needed several clarifying questions; a bug in the recursive base case produced extra results and time ran out.
Given n, return all combinations of n pairs of well-formed parentheses, in any order.
This is LeetCode 22 — Generate Parentheses.
Example
n = 3 -> ["((()))","(()())","(())()","()(())","()()()"]
n = 1 -> ["()"]
Constraints: 1 ≤ n ≤ 8.
Code runner format: one line with n. Implement generateParenthesis(n); any order is accepted (the harness sorts the result).