Get Outlier Value (Amazon London)
Learn this problemProblem 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:
int arr[n]: value ofn-2numbers, 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 = 16There 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^51 ≤ arr[i] ≤ 10^9
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026