Maximum Subarray With Equal Products

You are given an array of positive integers nums.

An array arr is called product equivalent if prod(arr) == lcm(arr) * gcd(arr), where:

  • prod(arr) is the product of all elements of arr.
  • gcd(arr) is the GCD of all elements of arr.
  • lcm(arr) is the LCM of all elements of arr.

Return the length of the longest product equivalent subarray of nums.

Example 1
Inputnums = [1,2,1,2,1,1,1]
Output5
The longest product equivalent subarray is [1, 2, 1, 1, 1], where its product is 2, its GCD is 1, and its LCM is 2.
Example 2
Inputnums = [2,3,4,5,6]
Output3
The longest product equivalent subarray is [3, 4, 5].

Constraints

  • 2 <= nums.length <= 100
  • 1 <= nums[i] <= 10

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate