Code Question 1
Amazon Prime Video has recently released an exclusive series on its platform. They collected the number of viewers from n
different regions across the world and stored the data in the array viewers_count
.
The success value of the release is defined as the sum of viewership in the top k
regions, those with the highest viewers.
For example, if viewers_count = [3, 2, 1, 4, 5]
and k = 3
, then the success value of the release is 3 + 4 + 5 = 12
as [3, 4, 5]
are the top 3 values.
Given a number of k
values, calculate the success value for each query.
Example
Input:
The viewership in 5 regions is viewers_count = [2, 5, 6, 3, 5]
, and we want to find the success value for 3 queries that are queries = [2, 3, 5]
.
Output:[11, 16, 21]
Explanation:
- For the first query,
k = 2
, the viewership of the top 2 regions is[6, 5]
. The success value is6 + 5 = 11
. - For the second query,
k = 3
, the viewership of the top 3 regions is[6, 5, 5]
and6 + 5 + 5 = 16
. - For the third query,
k = 5
, all 5 regions are used for the success value, and6 + 5 + 5 + 3 + 2 = 21
.
Function Description
Complete the function getViewValue in the editor below.
Parameters:
int viewers_count[n]
: An array representing the number of viewers in each region.int queries[q]
: An array of queries where each element representsk
.
Returns:
int[]
: An array where each element is the success value corresponding to a query inqueries
.
Code Question 2
Problem: Data Dependence in Time-Series Data
Description:
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 exists 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 (x
) on which the data of the x
th day (0 ≤ x ≤ n
) will be dependent.
Example
Suppose n = 5
.
x | k | floor(n / k) |
---|---|---|
0 | 6 | floor(5 / 6) = 0 |
1 | 5 | floor(5 / 5) = 1 |
2 | 2 | floor(5 / 2) = 2 |
3 | Does not exist | - |
4 | Does not exist | - |
5 | 1 | floor(5 / 1) = 5 |
The answer is the sum of all valid x
values: 0 + 1 + 2 + 5 = 8
.
Function Description
Complete the function getDataDependenceSum
in the editor below.
Parameters:
long int n
: The day to analyze the data dependency for.
Returns:
long int
: The sum of days on which the data is dependent.
Constraints
- The value of
n
is a positive integer. - Efficient computation is required for larger values of
n
.
我们长期稳定承接各大科技公司如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.