Panda Guru LogoPanda
Guru

TikTok | OA | Optimize TikTok Reels Viewing

Round 1

Questions: Optimize TikTok Reels Viewing

Problem Description: A content creator is taking on a challenge to get really good at TikTok. Instead of regular activities, they decide to focus on a playlist of n TikTok reels. To master TikTok, they set a goal to watch the reels a total of m times. But they want to do this in the least amount of time possible. Here’s how it works:

Function Description: Complete the function optimizeTikTokWatchTime in the editor below.

optimizeTikTokWatchTime has the following parameter(s):

Returns:

Example: Input:

n = 4 m = 4 initialWatch = [1, 5, 9, 11] repeatWatch = [2, 7, 10, 11]

Output:

9

Explanation: One of the optimal strategies can be: The creator watches the 0-th reel. As they are watching it for the first time, the time taken is initialWatch[0] + repeatWatch[0] = 1 + 2 = 3 minutes. The creator then rewatches the 0-th reel 3 times. So, the time taken is repeatWatch[0] * 3 = 2 * 3 = 6 minutes. Thus, the total time taken is 3 + 6 = 9 minutes.

Constraints: 1 <= n <= 10^5
1 <= m <= 10^9
1 <= initialWatch[i], repeatWatch[i] <= 10^9

Sample Input 0:

m = 5 initialWatch[] size n = 3 initialWatch = [6, 8, 9] repeatWatch[] size n = 3 repeatWatch = [4, 2, 10]

Sample Output 0:

26

Explanation 0: One of the optimal strategies is: The creator watches the 0-th reel. Since it’s the first time watching, the time taken is: initialWatch[0] + repeatWatch[0] = 6 + 4 = 10 minutes.

The learner watches the 1st video. As he is watching it for the first time, the time taken is: initialWatch[1] + repeatWatch[1] = 8 + 2 = 10 minutes.

The learner then rewatches the 1st video 3 times. So, the time taken is: repeatWatch[1] * 3 = 2 * 3 = 6 minutes.

Thus, the total time taken is: 10 + 10 + 6 = 26 minutes.

Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.