Ctrl K

All Ways to Factor a Number

Medium
You are given an integer number. Find every way to write it as a product of **two or more** integer factors, each at least 2 and less than number itself. Write each way as a list of factors in non-decreasing order, [2, 2, 3] rather than [3, 2, 2], so that no product is listed twice. Return all of them in any order. If there are none, return an empty list.
Example 1
number=18 → [[2, 9], [2, 3, 3], [3, 6]]

18 = 2 · 9 = 3 · 6 = 2 · 3 · 3. The lists may come in any order, but each one is non-decreasing.

Example 2
number=16 → [[2, 8], [2, 2, 4], [2, 2, 2, 2], [4, 4]]

16 = 2 · 8 = 4 · 4 = 2 · 2 · 4 = 2 · 2 · 2 · 2.

Example 3
number=13 → []

13 is prime, so it has no split into factors greater than 1 and less than 13.

Constraints
  • 1 ≤ number ≤ 10⁷
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsKeypad Words MediumAll Balanced Bracket Strings MediumWeight Sets for an Exact Load MediumCard Hands for an Exact Total MediumAll Orderings Medium
loading Python…
Input
number=18
Expected
[[2, 9], [2, 3, 3], [3, 6]]

Run checks the first 3 tests in your browser. Submit checks all 60 tests on the server, hidden ones included.