Class Solution
- java.lang.Object
-
- g2501_2600.s2584_split_the_array_to_make_coprime_products.Solution
-
public class Solution extends Object
2584 - Split the Array to Make Coprime Products.Hard
You are given a 0-indexed integer array
numsof lengthn.A split at an index
iwhere0 <= i <= n - 2is called valid if the product of the firsti + 1elements and the product of the remaining elements are coprime.- For example, if
nums = [2, 3, 3], then a split at the indexi = 0is valid because2and9are coprime, while a split at the indexi = 1is not valid because6and3are not coprime. A split at the indexi = 2is not valid becausei == n - 1.
Return the smallest index
iat which the array can be split validly or-1if there is no such split.Two values
val1andval2are coprime ifgcd(val1, val2) == 1wheregcd(val1, val2)is the greatest common divisor ofval1andval2.Example 1:
Input: nums = [4,7,8,15,3,5]
Output: 2
Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i. The only valid split is at index 2.
Example 2:
Input: nums = [4,7,15,8,3,5]
Output: -1
Explanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i. There is no valid split.
Constraints:
n == nums.length1 <= n <= 1041 <= nums[i] <= 106
- For example, if
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intfindValidSplit(int[] nums)
-