find all balanced braces

Solutions on MaxInterview for find all balanced braces by the best coders in the world

showing results for - "find all balanced braces"
Niko
22 Mar 2018
1void  find_balanced_braces(size_t const &n, size_t open, size_t close, size_t index, string &s, vector<string> &res){
2    if(open == n and close == n)
3        res.push_back(s);
4    else{
5        if(open < n){
6            s[index] = '(';
7            find_balanced_braces(n, open+1, close, index+1, s, res);
8        }
9        if(close < open){
10            s[index] = ')';
11            find_balanced_braces(n, open, close+1, index+1, s, res);
12        }
13    }
14}
15
16find_balanced_braces(n, 0, 0, 0, s, res);
similar questions
queries leading to this page
find all balanced braces