Description
Solutions
Maximize Engagement
🀘 INTERN

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. 1. int[] views: an array of integers representing the views
  2. 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 🐝
Constraints:
  • 1 <= n <= 2 * 105
  • 1 <= views[i], likes[i] <= 109
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: