3745. Maximize Expression of Three Elements Easy

@problem@discussion
#Array#Greedy#Sorting#Enumeration



1/**
2 * [3745] Maximize Expression of Three Elements
3 *
4 * You are given an integer array nums.
5 * Choose three elements a, b, and c from nums at distinct indices such that the value of the expression a + b - c is maximized.
6 * Return an integer denoting the maximum possible value of this expression.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [1,4,2,5]</span>
11 * Output: <span class="example-io">8</span>
12 * Explanation:
13 * We can choose a = 4, b = 5, and c = 1. The expression value is 4 + 5 - 1 = 8, which is the maximum possible.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [-2,0,5,-2,4]</span>
18 * Output: <span class="example-io">11</span>
19 * Explanation:
20 * We can choose a = 5, b = 4, and c = -2. The expression value is 5 + 4 - (-2) = 11, which is the maximum possible.
21 * </div>
22 *  
23 * Constraints:
24 * 
25 * 	3 <= nums.length <= 100
26 * 	-100 <= nums[i] <= 100
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/maximize-expression-of-three-elements/
32// discuss: https://leetcode.com/problems/maximize-expression-of-three-elements/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn maximize_expression_of_three(nums: Vec<i32>) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_3745() {
50    }
51}
52

Back
© 2026 bowen.ge All Rights Reserved.