2464. Minimum Subarrays in a Valid Split
You are given an integer array nums.
Splitting of an integer array nums into subarrays is valid if:
- the greatest common divisor of the first and last elements of each subarray is greater than 1, and
- each element of nums belongs to exactly one subarray.
Return the minimum number of subarrays in a valid subarray splitting of nums. If a valid subarray splitting is not possible, return -1.
Note that:
- The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
- A subarray is a contiguous non-empty part of an array.
1 | long long dp[1010]; |