FastPrepFastPrep
Problem Brief

Optimize TikTok Reels Viewing

INTERNOA
See Tiktok online assessment and hiring insights

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 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:

  • First Time Watching: The creator must watch each reel in the playlist completely the first time. The time it takes is initialWatch[i] + repeatWatch[i] for the i-th reel.
  • Rewatching: After the first complete watch, they can rewatch any reel in any order. For rewatching, they only spend repeatWatch[i] minutes per reel.
  • Sequential Viewing: When watching the playlist for the first time, they must watch the reels in order, from the first to the last.
  • Total Viewings: The total number of viewings (including first-time and rewatching) across all reels must add up to m.
  • Optimization Goal: The creator aims to minimize the total time spent watching the reels while fulfilling the above constraints. This involves strategically planning which reels to repeat and how often, given the reduced time for repeat viewings.

    Function Description

    Complete the function optimizeTikTokWatchTime in the editor below.

    optimizeTikTokWatchTime has the following parameter(s):

    1. int n: an integer denoting the total number of reel viewings the creator aims to complete.
    2. int initialWatch[n]: an integer array denoting the minutes to watch the i-th reel for the first time.
    3. int repeatWatch[n]: an integer array denoting the minutes to rewatch the i-th reel.
    4. int m: the target count of reel viewings.

    Returns

    int: an integer denoting the minimum total minutes required for the creator to reach their target (m) count of reel viewings.

    1Example 1

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

    Constraints

    Limits and guarantees your solution can rely on.

  • 1 <= n <= 105
  • 1 <= m <= 109
  • 1 <= initialWatch[i], repeatWatch[i] <= 109
  • public int optimizeTikTokWatchTime(int n, int[] initialWatch, int[] repeatWatch, int m) {
      // write your code here
    }
    
    Input

    n

    4

    initialWatch

    [1, 5, 9, 11]

    repeatWatch

    [2, 7, 10, 11]

    m

    4

    Output

    9

    Sign in to submit your solution.