You are a data analyst at the popular social media company TikTok. Your task is to optimize user engagement on TikTok-like video reels by developing an "engagement boost" algorithm that increases user interaction on the platform.
You are provided with two datasets: views
and likes
, both of the same length, where each entry represents the views and likes on a particular video. The objective is to maximize the "engagement score," defined as the sum of all likes[i]
where likes[i]
exceeds views[i]
.
However, there's a catch! You are allowed to rearrange the likes
dataset to maximize the engagement score, but the views
dataset remains fixed. Your challenge is to design an efficient algorithm that rearranges the likes
dataset to achieve the highest possible engagement score, while adhering to the constraint that the views
dataset cannot be rearranged.
Given two arrays of integers, views
and likes
, your goal is to rearrange the elements of likes
to maximize the engagement score.
Function Description
Complete the function maximizeEngagement
in the editor.
maximizeEngagement
has the following parameters:
- 1.
int[] views
: an array of integers representing the views - 2.
int[] likes
: an array of integers representing the likes
Returns
int
: the maximum engagement score
𫧠π³π ππΈ π π π π ππΈCouldnβt have done it without Aππ
Example 1:
Input: views = [2, 3, 4, 5, 6], likes = [4, 6, 5, 7, 3]
Output: 25
Explanation:The likes array can be rearrange to [3, 4, 5, 6, 7]. Now, for each index, the likes array has integers greater than the corresponding values in views. Thus, the sum is 3 + 4 + 5 + 6 + 7 = 25 π¦
Example 2:
Input: views = [2, 5, 3, 2, 4], likes = [3, 4, 2, 3, 3]
Output: 10
Explanation:The likes array can be rearranged to [3, 2, 4, 3, 3]. For i = 0, 2, and 3, likes[i] > views[i], and the engagement score is 3 + 4 + 3 = 10.
Example 3:
Input: views = [2, 10, 5, 3], likes = [9, 5, 4, 2]
Output: 18
Explanation:The likes array can be rearrange to [4, 2, 9, 5]. For i = 0, 2, and 3, likes[i] > views[i], and the engagement score is 4 + 9 + 5 = 18 π
1 <= n <= 2 * 105
1 <= views[i], likes[i] <= 109


input:
output: