1913. Maximum Product Difference Between Two Pairs Easy
1/**
2 * [1913] Maximum Product Difference Between Two Pairs
3 *
4 * The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).
5 *
6 *
7 * For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.
8 *
9 *
10 * Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.
11 *
12 * Return the maximum such product difference.
13 *
14 *
15 * Example 1:
16 *
17 *
18 * Input: nums = [5,6,2,7,4]
19 * Output: 34
20 * Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
21 * The product difference is (6 * 7) - (2 * 4) = 34.
22 *
23 *
24 * Example 2:
25 *
26 *
27 * Input: nums = [4,2,5,9,7,4,8]
28 * Output: 64
29 * Explanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
30 * The product difference is (9 * 8) - (2 * 4) = 64.
31 *
32 *
33 *
34 * Constraints:
35 *
36 *
37 * 4 <= nums.length <= 10^4
38 * 1 <= nums[i] <= 10^4
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/maximum-product-difference-between-two-pairs/
44// discuss: https://leetcode.com/problems/maximum-product-difference-between-two-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn max_product_difference(nums: Vec<i32>) -> i32 {
50
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_1913() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.