[Amazon] SDE intern oa 12.26

Code Question 1

AWS provides many services for outlier detection. A prototype small service to detect an outlier in an array of 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.


Example
n = 6
arr = [4, 1, 3, 16, 2, 10]

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. (It is not an original number or their sum.)
  • Remove 4 - arr' = [1, 3, 16, 2, 10]. The sum of [1, 3, 16, 2] is 16, so 4 is a potential outlier.

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


Code Question 2

Developers at Amazon are building a multi-process analysis tool to analyze the computational intensity of the processes. There are n processes and the i-th process needs process[i] computation resources for completion.

Two processes are considered to be computationally the same if their resource requirements differ by at most k.

Given the array process and an integer k, find the number of pairs of processes that are computationally the same.


Example
n = 4 and process = [7, 10, 13, 11] and k = 3

The process pairs are:

PairsDifferenceComputationally Same
(7, 10)7 - 10
(7, 13)7 - 13
(7, 11)7 - 11
(10, 13)10 - 13
(10, 11)10 - 11
(13, 11)13 - 11

Hence the answer is 4.


Function Description
Complete the function getPairsCount in the editor below.

getPairsCount takes the following arguments:

  • int process[n]: the computational resource requirement of the processes
  • int k: the threshold for being computationally the same

Returns

  • long int: the number of pairs of processes that are computationally the same.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *