Find Least Possible Vulnerability
Learn this problemProblem statement
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.
Function
findLeastPossibleVulnerability(key: int[], maxChange: int) → intComplete the function findLeastPossibleVulnerability in the editor below. It has the following parameters:
int[] key: the original encryption key arrayint maxChange: the maximum number of elements that can be changed
Returns
int: the least possible vulnerability factor of the key after performing at mostmaxChangemodifications.
Examples
Example 1
key = [2, 2, 4, 9, 6]maxChange = 1return = 2Example 2
key = [5, 10, 20, 10, 15, 5]maxChange = 2return = 2Example 3
key = [4, 2, 4]maxChange = 1return = 1Example 4
key = [3, 5, 7, 11, 13]maxChange = 2return = 0Constraints
1 ≤ n ≤ 10^50 ≤ maxChange ≤ n1 ≤ key[i] ≤ 10^9
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026