Find Least Possible Vulnerability
Note π - Another problem related to find server vulnerability Find Kth Minimum Vulnerability πΉ
A great solution insight from a pro in the server. Hope it helps you solve this problem! π
Another pro in the server mentioned that this problem is similar to LC 1004. Hopefully, the similarity can help bring some insights for you. Happi Coding! You are not alone! π«Ά
Developers at Amazon IAM are working on identifying vulnerabilities in their key generation process. The key is represented as an array of n integers, where the i-th integer is denoted by key[i]
The vulnerability factor of the array is defined as the maximum length of a contiguous subarray that has a Greatest Common Divisor (GCD) greater than 1.
You are allowed to make at most maxChange modifications to the array, where each modification consists of changing any one element in the array to any other integer.
Your task is to determine the least possible vulnerability factor of the key after performing at most maxChange modifications.
If no valid subarray has GCD > 1, the vulnerability factor is considered 0.
Complete the function findLeastPossibleVulnerabilityFactor in the editor.
findLeastPossibleVulnerability has the following parameters:
- 1.
int[] key: an array of integers - 2.
int maxChange: the maximum number of changes allowed
Returns
int: the least possible vulnerability factor of the array after performing at most maxChange modifications.
A heartfelt thank you to all the amazing friends who so generously offered their help in completing this question! π·
1Example 1
2Example 2
3Example 3
4Example 4
Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 10^50 <= maxChange <= n1 <= key[i] <= 10^9