Problem · Greedy

Optimize TikTok Reels Viewing

Learn this problem
MediumTiktokINTERNOA
See Tiktok hiring insights

Problem statement

A content creator wants to complete exactly m total viewings from a playlist of n TikTok reels in the least possible time.

  • The first-time viewings must follow playlist order. You may stop after unlocking any prefix of the reels.
  • The first viewing of reel i takes initialWatch[i] + repeatWatch[i] minutes.
  • After a reel has been watched once, each additional viewing of it takes repeatWatch[i] minutes.
  • Rewatches may use any already unlocked reel and may occur in any order.

Return the minimum total time required to complete exactly m viewings.

Function

optimizeTikTokWatchTime(n: int, initialWatch: int[], repeatWatch: int[], m: int) → long

Examples

Example 1

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

Unlock only the first reel for 1 + 2 = 3 minutes, then rewatch it three times for 3 * 2 = 6 minutes. The total is 3 + 6 = 9.

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ m ≤ 10^9
  • initialWatch.length = repeatWatch.length = n
  • 1 ≤ initialWatch[i], repeatWatch[i] ≤ 10^9

More Tiktok problems

drafts saved locally
public long optimizeTikTokWatchTime(int n, int[] initialWatch, int[] repeatWatch, int m) {
  // write your code here
}
n4
initialWatch[1, 5, 9, 11]
repeatWatch[2, 7, 10, 11]
m4
expected9
checking account