3371. Identify the Largest Outlier in an Array Medium
1/**
2 * [3371] Identify the Largest Outlier in an Array
3 *
4 * You are given an integer array nums. This array contains n elements, where exactly n - 2 elements are special numbers. One of the remaining two elements is the sum of these special numbers, and the other is an outlier.
5 * An outlier is defined as a number that is neither one of the original special numbers nor the element representing the sum of those numbers.
6 * Note that special numbers, the sum element, and the outlier must have distinct indices, but may share the same value.
7 * Return the largest potential outlier in nums.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">nums = [2,3,5,10]</span>
12 * Output: <span class="example-io">10</span>
13 * Explanation:
14 * The special numbers could be 2 and 3, thus making their sum 5 and the outlier 10.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">nums = [-2,-1,-3,-6,4]</span>
19 * Output: <span class="example-io">4</span>
20 * Explanation:
21 * The special numbers could be -2, -1, and -3, thus making their sum -6 and the outlier 4.
22 * </div>
23 * <strong class="example">Example 3:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [1,1,1,1,1,5,5]</span>
26 * Output: <span class="example-io">5</span>
27 * Explanation:
28 * The special numbers could be 1, 1, 1, 1, and 1, thus making their sum 5 and the other 5 as the outlier.
29 * </div>
30 *
31 * Constraints:
32 *
33 * 3 <= nums.length <= 10^5
34 * -1000 <= nums[i] <= 1000
35 * The input is generated such that at least one potential outlier exists in nums.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/identify-the-largest-outlier-in-an-array/
41// discuss: https://leetcode.com/problems/identify-the-largest-outlier-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn get_largest_outlier(nums: Vec<i32>) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3371() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.