hardArrayBinary SearchGreedyMathNumber TheorySegment Tree 0 views

Minimum Stability Factor of Array

You are given an integer array nums and an integer maxC.

You are given an integer array nums and an integer maxC.

A subarray is called stable if the highest common factor (HCF) of all its elements is greater than or equal to 2.

The stability factor of an array is defined as the length of its longest stable subarray.

You may modify at most maxC elements of the array to any integer.

Return the minimum possible stability factor of the array after at most maxC modifications. If no stable subarray remains, return 0.

Note:

Minimum Stability Factor of Array diagram

Example 1

Input: nums = [3,5,10], maxC = 1

Output: 1

Example 2

Input: nums = [2,6,8], maxC = 2

Output: 1

Example 3

Input: nums = [2,4,9,6], maxC = 1

Output: 2

Constraints

  • 1 <= n == nums.length <= 10^5
  • 1 <= nums[i] <= 10^9
  • 0 <= maxC <= n

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.