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 num_viewers.
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 num_viewers = [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.
Complete the function getSuccessValue in the editor.
getSuccessValue has the following parameters:
int num_viewers[n]: viewership from n different regionsint queries[q]: an array of k valuesReturns
int[q]: the maximum possible success values for each queryExamples
01 Β· Example 1
num_viewers = [2, 5, 6, 3, 5] queries = [2, 3, 5] return = [11, 16, 21]
The viewership in 5 regions is num_viewers = [2, 5, 6, 3, 5], and we want to find the success value for 3 queries that are queries = [2, 3, 5].
For the first query, k = 2, the viewership of the top 2 regions is [6, 5]. The success value is 6 + 5 = 11.
For the second query, k = 3, the viewership of the top 3 regions is [6, 5, 5] and 6 + 5 + 5 = 16.
For the third query, k = 5, all the 5 regions are used for the success value and 6 + 5 + 5 + 3 + 2 = 21.
Return [11, 16, 21].
02 Β· Example 2
num_viewers = [7, 3, 5, 2] queries = [1, 4] return = [7, 17]
For the first query, k = 1, only the top region is used for the success value.
For the second query, k = 4, all 4 regions are used.
Return [7, 17].
03 Β· Example 3
num_viewers = [7, 5, 6] queries = [1, 2, 3] return = [7, 13, 18]
For the first query, k = 1, only the top region is used for the success value.
For the second query, k = 2, only the top 2 regions are used.
For the third query, k = 3, all 3 regions are used.
Return [7, 13, 18].
Constraints
1 <= n <= 10^51 <= q <= 10^51 <= num_viewers[i] <= 10^91 <= queries[i] <= nMore Amazon problems
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA Β· Seen Jun 2026
- Get Minimum AmountOA Β· Seen Jun 2026
- Drone Delivery RouteOA Β· Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Minimum Operations to Make Array ValidOA Β· Seen Jun 2026
- Sort Bug Report FrequenciesOA Β· Seen Jun 2026
public int[] getSuccessValue(int[] queries, int[] num_viewers) {
// write your code here
}
num_viewers[2, 5, 6, 3, 5]
queries[2, 3, 5]
expected[11, 16, 21]
checking account