Leetcode Problem of the Day Solution
Anonymous user02 Oct 2026
#Leetcode#Leetcode POTD#Leetcode Problem of the Day#Leetcode POTD Solution
It is recommended to first try at your own. 2 Oct 2026
The Leetcode POTD solution is given below:
class Solution {
public:
void f(int n,string newStr,int open,int close,vector<string> &ans){
if(open==n && close==n){
ans.push_back(newStr);
}
if(open<n){
f(n,newStr+"(",open+1,close,ans);
}
if(open>close) f(n,newStr+")",open,close+1,ans);
}
vector<string> generateParenthesis(int n) {
vector<string> ans;
f(n,"",0,0,ans);
return ans;
}
};