Skip to main content
All Questions

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 courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.