Partition Array into Two Equal Product Subsets

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.

Example 1
Inputnums = [3,1,6,8,4], target = 24
Outputtrue
The subsets [3, 8] and [1, 6, 4] each have a product of 24, so such a partition exists.
Example 2
Inputnums = [2,5,3,7], target = 15
Outputfalse
There is no way to partition nums into two non-empty disjoint subsets such that both subsets have a product of 15.

Constraints

  • 3 <= nums.length <= 12
  • 1 <= target <= 10^15
  • 1 <= nums[i] <= 100
  • All elements of nums are distinct.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate