1464. Maximum Product of Two Elements in an Array Easy

@problem@discussion
#Array#Sorting#Heap (Priority Queue)



1/**
2 * [1464] Maximum Product of Two Elements in an Array
3 *
4 * Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).
5 *  
6 * Example 1:
7 * 
8 * Input: nums = [3,4,5,2]
9 * Output: 12 
10 * Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12. 
11 * 
12 * Example 2:
13 * 
14 * Input: nums = [1,5,4,5]
15 * Output: 16
16 * Explanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.
17 * 
18 * Example 3:
19 * 
20 * Input: nums = [3,7]
21 * Output: 12
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	2 <= nums.length <= 500
27 * 	1 <= nums[i] <= 10^3
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/
33// discuss: https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn max_product(nums: Vec<i32>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_1464() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.