3411. Maximum Subarray With Equal Products Easy

@problem@discussion
#Array#Math#Sliding Window#Enumeration#Number Theory



1/**
2 * [3411] Maximum Subarray With Equal Products
3 *
4 * You are given an array of positive integers nums.
5 * An array arr is called product equivalent if prod(arr) == lcm(arr) * gcd(arr), where:
6 * 
7 * 	prod(arr) is the product of all elements of arr.
8 * 	gcd(arr) is the <span data-keyword="gcd-function">GCD</span> of all elements of arr.
9 * 	lcm(arr) is the <span data-keyword="lcm-function">LCM</span> of all elements of arr.
10 * 
11 * Return the length of the longest product equivalent <span data-keyword="subarray-nonempty">subarray</span> of nums.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,2,1,2,1,1,1]</span>
16 * Output: <span class="example-io">5</span>
17 * Explanation: 
18 * The longest product equivalent subarray is [1, 2, 1, 1, 1], where prod([1, 2, 1, 1, 1]) = 2, gcd([1, 2, 1, 1, 1]) = 1, and lcm([1, 2, 1, 1, 1]) = 2.
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">nums = [2,3,4,5,6]</span>
23 * Output: <span class="example-io">3</span>
24 * Explanation: 
25 * The longest product equivalent subarray is [3, 4, 5].
26 * </div>
27 * <strong class="example">Example 3:
28 * <div class="example-block">
29 * Input: <span class="example-io">nums = [1,2,3,1,4,5,1]</span>
30 * Output: <span class="example-io">5</span>
31 * </div>
32 *  
33 * Constraints:
34 * 
35 * 	2 <= nums.length <= 100
36 * 	1 <= nums[i] <= 10
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/maximum-subarray-with-equal-products/
42// discuss: https://leetcode.com/problems/maximum-subarray-with-equal-products/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn max_length(nums: Vec<i32>) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_3411() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.