Mid
Backtracking
DSA & Coding Interviews
How do you solve Subsets / Permutations with backtracking?
Short answer: Subsets: at each index choose include/exclude (or loop-based cascading). Permutations: swap/choose unused elements recursively. Always discuss time complexity exponential in n and when to prune.
Complexity
Subsets O(n * 2^n); Permutations O(n * n!).
Draw the decision tree for n=3 — it proves you understand recursion depth.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png