Skip to content

Interview Questions

#ProblemKey ConceptApproach
1FactorialBasic recursionf(n) = n * f(n-1)
2FibonacciTree recursion + memoizationf(n) = f(n-1) + f(n-2)
3Sum of digitsExtract last digit(n % 10) + f(n/10)
4Power of twoDivide by 2f(n) = n===1 ? true : n%2===0 && f(n/2)
5Reverse stringHead recursionSwap, recurse inward
6Palindrome checkTwo pointersCompare first & last, recurse inward
7Print 1 to NHead vs tail recursionPrint before or after recursive call
8Count occurrencesLinear scanCheck current + recurse rest

Quick solutions:

// Sum of digits
function digitSum(n) {
if (n === 0) return 0;
return (n % 10) + digitSum(Math.floor(n / 10));
}
// Palindrome check
function isPalindrome(str, left = 0, right = str.length - 1) {
if (left >= right) return true;
if (str[left] !== str[right]) return false;
return isPalindrome(str, left + 1, right - 1);
}
// Power of two check
function isPowerOfTwo(n) {
if (n === 1) return true;
if (n === 0 || n % 2 !== 0) return false;
return isPowerOfTwo(n / 2);
}
#ProblemKey ConceptApproach
1SubsetsPick/Not-pickBinary decisions for each element
2Subsets II (with duplicates)Sort + skip duplicatesif(i > start && nums[i]===nums[i-1]) skip
3PermutationsUsed array / swappingTry all unused elements at each position
4Permutations II (with duplicates)Sort + skip duplicatesif(i > 0 && nums[i]===nums[i-1] && !used[i-1]) skip
5Combination SumUnlimited reusePass index (not index+1) for reuse
6Combination Sum IIEach used onceSort + skip duplicates + i+1
7Generate ParenthesesOpen/close countsopen < n and close < open rules
8Letter CombinationsMultiple choices per digitMap digit → letters, iterate + recurse
9Palindrome PartitioningPartition + checkTry all prefixes that are palindromes
10Word SearchGrid backtracking4-direction DFS with visited tracking
#ProblemKey ConceptApproach
1N-QueensRow-by-row + diagonal trackingSets for cols/diags, try each col per row
2Sudoku SolverCell-by-cell + validity checkTry 1-9, validate row/col/box
3Word Break IIRecursion + string partitioningTry all prefixes in dictionary
4Expression Add OperatorsString + math operationsInsert +, -, * between digits
5Unique Paths IIIGrid + visit all cellsDFS with backtracking on grid
6Rat in a MazeGrid path finding4-direction DFS with visited
7Knight’s TourChess board traversal8 possible moves, visit all 64 squares
8Tug of WarPartition into halvesSubset selection minimizing diff
Week 1: RECURSION BASICS
□ Factorial □ Fibonacci □ Sum of N numbers
□ Power (xⁿ) □ Print 1 to N □ Reverse string
□ Check palindrome □ Sum of digits
Week 2: RECURSION INTERMEDIATE
□ Print all subsequences □ Subsequences with sum K
□ Merge Sort □ Tower of Hanoi
Week 3: BACKTRACKING FUNDAMENTALS
□ Subsets □ Subsets II (with duplicates)
□ Permutations □ Permutations II
□ Combination Sum □ Combination Sum II
□ Generate Parentheses
Week 4: BACKTRACKING ADVANCED
□ Palindrome Partitioning □ Word Search
□ N-Queens □ Sudoku Solver
□ Letter Combinations □ Rat in a Maze

Next: Common Mistakes & Tips →