Minimize the longest subarray with GCD greater than 1.
Unlock detailed company stats for this questionUpgrade
Developers at Amazon IAM identify vulnerabilities in key generation. The key is an array of n integers. The vulnerability factor is the maximum length of a contiguous subarray with GCD greater than 1 (0 if no such subarray). You may make at most maxChange modifications, each changing any one element to any other integer. Implement findLeastPossibleVulnerabilityFactor(int[] key, int maxChange), returning the least possible vulnerability factor. Examples: key = [2, 2, 4, 9, 6], maxChange = 1 gives 2; key = [5, 10, 20, 10, 15, 5], maxChange = 2 gives 2; key = [4, 2, 4], maxChange = 1 gives 1; key = [3, 5, 7, 11, 13], maxChange = 2 gives 0. Constraints: 1 <= n <= 10^5, 0 <= maxChange <= n, 1 <= key[i] <= 10^9.
Community answers
No answers contributed by the community yet.
Related questions
Find the longest subarray with equal 0s and 1s and no prefix with more 0s than 1s.Find the length of the longest subarray with sum equal to 0.Given an array, find the length of the longest subarray with sum less than or equal to k.Related courses

Course

Course
Course
