#3605
Minimum Stability Factor of Array
grandmaster · 2200 · lc hard +32 · 20.3% accepted · 41 likes · top 2%
Description
An integer array nums and integer maxC are given. A subarray is stable when the HCF of all its elements is at least 2. The stability factor is the length of the longest stable subarray.
You may change at most maxC elements to any integer value.
Return the minimum possible stability factor after modifications. Return 0 if no stable subarray can remain.
Notes:
- HCF is the largest integer dividing all elements evenly.
- A length-1 subarray with value x >= 2 is stable since HCF([x]) = x.
Code
1
2
3