Factor Combinations
Question (LC.254)
Example
I: 8
O: [ [2,2,2], [2,4] ]
I: 1
O: []
I: 2
O: []
I: 9
O: [ [3,3] ]Attempt #1
1. Define subproblem
factorSearch(result, factors, dividend) =>
add all factor combinations of dividend to result (with given prefix factors)
2. Recursive calls
for factor from 2 to dividend / 2
if (divident % factor != 0) continue
factorSearch(result, factors.add(factor), divident / factor)
3. Bases cases
if (dividend == 1)
result.add(new List(factors))Corrected Code
Time & Space Complexity
Last updated