Partition Array into Two Equal Product Subsets - Problem
You are given an integer array nums containing distinct positive integers and an integer target.
Determine if you can partition nums into two non-empty disjoint subsets, with each element belonging to exactly one subset, such that the product of the elements in each subset is equal to target.
Return true if such a partition exists and false otherwise.
A subset of an array is a selection of elements of the array.
Input & Output
Example 1 — Valid Partition
$
Input:
nums = [2,3,6], target = 6
›
Output:
true
💡 Note:
We can partition into {2,3} and {6}. Product of {2,3} = 2×3 = 6, Product of {6} = 6. Both equal target.
Example 2 — No Valid Partition
$
Input:
nums = [1,2,3], target = 4
›
Output:
false
💡 Note:
Total product is 1×2×3 = 6, but we need both subsets to have product 4, requiring total product = 16. Impossible.
Example 3 — Single Element Match
$
Input:
nums = [4,1], target = 4
›
Output:
true
💡 Note:
Partition into {4} and {1}. But product of {1} = 1 ≠ 4, so this is actually false.
Constraints
- 2 ≤ nums.length ≤ 10
- 1 ≤ nums[i] ≤ 100
- nums contains distinct integers
- 1 ≤ target ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [2,3,6] and target 6
2
Process
Try different partitions and calculate products
3
Output
Return true if valid partition exists
Key Takeaway
🎯 Key Insight: Both subsets must have product = target, so total product must equal target²
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code