[InterviewBit] All Possible Combinations

All Possible Combinations

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void helper(vector<string>& A, vector<string>& res, int p, string& now) {
if(p == A.size()) res.push_back(now);
else {
for(auto& ch : A[p]) {
now.push_back(ch);
helper(A,res,p+1,now);
now.pop_back();
}
}
}

vector<string> Solution::specialStrings(vector<string> &A) {
vector<string> res;
string now = "";
for(auto& a : A) sort(begin(a), end(a));
helper(A,res,0, now);
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/18/PS/interviewbit/all-possible-combinations/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.