Problem · Array

Get Outlier Value (Amazon London)

Learn this problem
EasyAmazonINTERNOA
See Amazon hiring insights

Problem statement

AWS provides many services for outlier detection. A prototype small service to detect an outlier in an array of n integers is under development.

Given an array of n integers, there are (n - 2) normal numbers and the sum of the (n - 2) numbers originally in this array. If a number is neither in the original numbers nor is it their sum, it is an outlier. Discover the potential outliers and return the greatest of them.

Note: It is guaranteed that the answer exists.

Function

getOutlierValue(arr: int[]) → int

Complete the function getOutlierValue in the editor.

getOutlierValue has the following parameters:

  1. int arr[n]: value of n-2 numbers, their sum, and outlier value

Returns

int: the outlier value

𓂃 ོ𓂃𓍼ོོོོོ 🐳 chizzy_elect is the real MVP!ᡣ𐭩𓂃 𓈒𓏸

Examples

Example 1

arr = [4, 1, 3, 16, 2, 10]return = 16

There are two potential outliers:

  • Remove 16: arr - [4, 1, 3, 2, 10]. The sum of [4, 1, 3, 2] is 10, so 16 is a potential outlier. (16 is not an original number nor their sum.)
  • Remove 4: arr - [1, 3, 16, 2, 10]. The sum of [1, 3, 2, 10] is 16, so 4 is a potential outlier.

The outlier is the greater of the two potential outliers, so 16 is the outlier.

Constraints

  • 3 ≤ n ≤ 10^5
  • 1 ≤ arr[i] ≤ 10^9

More Amazon problems

drafts saved locally
public int getOutlierValue(int[] arr) {
  // write your code here
}
arr[4, 1, 3, 16, 2, 10]
expected16
checking account