Backtracking used for to get all possible solutions.
void backtrack(arguments) {
if (condition == true) { // Condition when we should stop our exploration.
result.push_back(current);
return;
}
for (int i = num; i <= last; i++) {
current.push_back(i); // Choose candidate.
backtrack(arguments); // Explore more
current.pop_back(); // Remove candidate.
}
}
Popular Questions
All Possible Combinations
Input 1:
A = ['ab', 'cd']
Example Output
Output 1:
['ac', 'ad', 'bc', 'bd']
CODE -- ACCORDING TO OUR PATTERN

SUBSET Example Input
A = [1, 2, 3]
Example Output
[
[],
[1],
[1, 2],
[1, 2, 3],
[1, 3],
[2],
[2, 3],
[3],
]
Combination Sum
Example Input
Input 1:
A = [2, 3] B = 2
Input 2:
A = [2, 3, 6, 7] B = 7
Example Output
Output 1:
[ [2] ]
Output 2:
[ [2, 2, 3], [7] ]
Combination Sum2
Only diff in combination sum and this problem is duplicate not allowed so we move to next index asap
Input and output
SubSet2
The only difference between this and the subset problem is, here we store results in set to avoid duplicates while in the set question we used ArrayList to get all subsets including duplicates
Letter Phone
Input
Output
Used All Possible Sum Approach
Permutation
Input
Output
N QUEEN
Output











