The marketing team at Amazon is experimenting with the number of reviews for each product.
You are given an array reviews
of size n
, where reviews[i]
represents the number of reviews for the i-th product. There are APIs available to add or remove reviews, where each API call can either add or remove one review.
Given an integer array counts
of size q
, your task is to calculate the number of API calls required to change the review count of each product in reviews
to match each value in the counts
array.
The goal is to return an array of size q
, where the i-th element denotes the total number of API calls needed to change the review count of all products to match counts[i]
.
Function Description
Complete the function findNetworkCalls
in the editor below.
findNetworkCalls
has the following parameters:
int reviews[]
: the initial count of reviews of each productint counts[]
: the equal count of reviews
Returns
long[]
: the number of API calls to be made to change the review count of each product.
🌷 ᡣ𐭩જ⁀➴All Credit goes to interested_max ༊·˚
Example 1:
Input: reviews = [4, 6, 5, 2, 1], counts = [3]
Output: [9]
Explanation:Therefore, the total API calls made to change the number of reviews for all products to 3 is: 1 + 3 + 2 + 1 + 2 = 9. Hence, return the array [9].
- 1 ≤ n ≤ 10^5
- 1 ≤
reviews[i]
≤ 10^6 - 1 ≤ q ≤ 10^5
- 1 ≤
counts[i]
≤ 10^6

input:
output: