Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Factor Combinations
MEDIUM
35 mins
4 upvotes
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Factor Combinations

Contributed by
Yash_5830
Medium
yellow-spark
0/80
Avg time to solve 35 mins
Success Rate 65 %
Share
4 upvotes

Problem Statement

You are given a positive integer ‘N’. Find all the unique combinations of factors of the given number ‘N’. The product of the factors in each combination should be ‘N’.

You should return a list of combinations of factors. In each combination, factors must be sorted in non-decreasing order. All combinations must be placed in lexicographical order in the list. See the example for more clarity.

Note

1. Factors should be strictly greater than 1 and strictly less than ‘N’.

2. If there is no such possible combination of factors, then return an empty list. 

Example:

Consider the positive integer ‘N’ = 12.
Then, we can observe that -:
12 = 2 * 2 * 3
12 = 2 * 6
12 = 3 * 4

i.e,  possible combinations of factors are [2, 2, 3], [2, 6], [3, 4].
Thus, we should return list [[2,2,3], [2,6], [3, 4]].  Note that in this list all combinations are sorted in non-decreasing order, and all the combinations in the list are placed in the lexicographical order.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
5
12
Sample Output 1:
0
3
2 2 3
2 6
3 4
Explanation of Sample Input 1:
Test case 1:
The integer 5 is a prime number, and it has no factors. Note, we consider that factors should be strictly greater than 1 and strictly less than ‘N’.

Test case 2:
See the problem statement for an explanation.
Sample Input 2:
2
16
4
Sample Output 2:
4
2 2 2 2 
2 2 4 
2 8 
4 4 
1
2 2
Reset Code
Full screen
Auto
copy-code
Console