Identify the Largest Outlier in an Array

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.

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.

Note that special numbers, the sum element, and the outlier must have distinct indices, but may share the same value.

Return the largest potential outlier in nums.

Example 1
Inputnums = [2,3,5,10]
Output10
The special numbers could be 2 and 3, thus making their sum 5 and the outlier 10.
Example 2
Inputnums = [-2,-1,-3,-6,4]
Output4
The special numbers could be -2, -1, and -3, thus making their sum -6 and the outlier 4.

Constraints

  • 3 <= nums.length <= 10^5
  • -1000 <= nums[i] <= 1000
  • The input is generated such that at least one potential outlier exists in nums.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate