3411. Maximum Subarray With Equal Products
3411. Maximum Subarray With Equal Products
Description
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 ofarr.gcd(arr)is the GCD of all elements ofarr.lcm(arr)is the LCM of all elements ofarr.
Return the length of the longest product equivalent subarray of nums.
Example 1:
1 | Input: nums = [1,2,1,2,1,1,1] |
Explanation:
The longest product equivalent subarray is [1, 2, 1, 1, 1], whereprod([1, 2, 1, 1, 1]) = 2,gcd([1, 2, 1, 1, 1]) = 1, andlcm([1, 2, 1, 1, 1]) = 2.
Example 2:
1 | Input: nums = [2,3,4,5,6] |
Explanation:
The longest product equivalent subarray is [3, 4, 5].
Example 3:
1 | Input: nums = [1,2,3,1,4,5,1] |
Constraints:
2 <= nums.length <= 1001 <= nums[i] <= 10
Hints/Notes
- 2025/01/12
- 0x3Fâs solution(checked)
- Weekly Contest 431
Solution
Language: C++
1 | class Solution { |