Factor Combinations - Problem

Numbers can be regarded as the product of their factors. For example, 8 = 2 × 2 × 2 = 2 × 4.

Given an integer n, return all possible combinations of its factors. You may return the answer in any order.

Note: The factors should be in the range [2, n - 1].

Input & Output

Example 1 — Basic Case
$ Input: n = 12
Output: [[2,6],[2,2,3],[3,4]]
💡 Note: 12 can be factored as 2×6, 2×2×3, or 3×4. All factors must be in range [2, 11]
Example 2 — Single Factor Pair
$ Input: n = 8
Output: [[2,4],[2,2,2]]
💡 Note: 8 can be factored as 2×4 or 2×2×2
Example 3 — Prime Number
$ Input: n = 37
Output: []
💡 Note: 37 is prime, so it has no factors in range [2, 36]

Constraints

  • 1 ≤ n ≤ 107
  • Factors must be in range [2, n-1]

Visualization

Tap to expand
Factor Combinations: Breaking Down NumbersInputn = 12Process: Find Factor Combinations2×6, 2×2×3, 3×4Output[[2,6],[2,2,3],[3,4]]2 × 6 = 12[2,6]2×2×3 = 12[2,2,3]3 × 4 = 12[3,4]All factor combinations where factors are in range [2, n-1]
Understanding the Visualization
1
Input
Given number n = 12
2
Process
Find all ways to multiply factors to get 12
3
Output
Return all valid factor combinations
Key Takeaway
🎯 Key Insight: Use backtracking to systematically explore all valid factor combinations while avoiding duplicates
Asked in
Google 15 Facebook 12 Amazon 8
23.0K Views
Medium Frequency
~25 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen