1. Code Question 1
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 m
.
Given the array process
and an integer m
, find the number of pairs of processes that are computationally the same.
Example
Suppose n = 4
, process = [7, 10, 13, 11]
, and m = 3
.
Pairs | Difference | Computationally 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 |
The result is 4 pairs.
Function Description
Complete the function getComputationalEquivalents
in the editor below.
getComputationalEquivalents
has the following parameters:
- int process[n]: the computational resource requirement of the processes.
- int m: the threshold for being computationally the same.
Returns
- long int: the number of pairs of processes that are computationally the same.
Constraints
1 <= n <= 200,000
1 <= process[i] <= 1,000,000
0 <= m <= 1,000,000
Sample Case 0
Input
STDIN FUNCTION
----- --------
4 process[] size n = 4
100 200 300 400 process = [100, 200, 300, 400]
250 m = 250
Output
5
Explanation
The computationally-same processes are:
- (100, 200)
- (100, 300)
- (200, 300)
- (200, 400)
- (300, 400)
Thus, the result is 5.
Sample Case 1
Input
STDIN FUNCTION
----- --------
3 process[] size n = 3
10 12 11 process = [10, 12, 11]
0 m = 0
Output
0
Explanation
All the pairs of processes have differences between computational resource requirements greater than 0.
2. Code Question 2
Data analysts at Amazon are analyzing time-series data. It was concluded that the data of the n-th
item was dependent on the data of some x-th
day if there is a positive integer k
such that floor(n / k) = x
, where floor(z)
represents the largest integer less than or equal to z
.
Given n
, find the sum of all the days' numbers on which the data of the x-th
(0 ≤ x ≤ n) will be dependent.
Example
Suppose n = 5
.
x | k | floor(n / k) |
---|---|---|
6 | Does not exist | - |
5 | floor(5 / 5) = 1 | 1 |
2 | floor(5 / 2) = 2 | 2 |
3 | Does not exist | - |
4 | Does not exist | - |
1 | floor(5 / 1) = 5 | 5 |
Hence the answer is 0 + 1 + 2 + 5 = 8
.
Function Description
Complete the function getDataDependenceSum
in the editor below.
getDataDependenceSum
takes the following arguments:
- long int n: the day to analyze the data dependency for
Returns
- long int: the sum of all the dependent days' numbers
Constraints
1 ≤ n ≤ 10^10
Sample Case 0
Input
STDIN FUNCTION
----- --------
13 n = 13
Output
29
Explanation
The data of n = 13
-th day is dependent on [0, 1, 2, 3, 4, 6, 13]
obtained for k = [14, 13, 6, 4, 3, 2, 1]
.
Sample Case 1
Input
STDIN FUNCTION
----- --------
1 n = 1
Output
1
Explanation
The only dependency is 1
.
我们长期稳定承接各大科技公司如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.