PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/TikTok

Maximize watched duration under consecutive-sum limit

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving in sequence optimization and constraint-based selection, testing competencies such as dynamic programming, subsequence selection, and handling pairwise adjacency constraints.

  • easy
  • TikTok
  • Coding & Algorithms
  • Data Scientist

Maximize watched duration under consecutive-sum limit

Company: TikTok

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You have a list of videos in a feed. Video *i* has duration `d[i]` (positive integer). A user has an “attention span” limit `A`. You want to select a **subset of videos to watch** (keeping the original order, i.e., choose a subsequence of indices `i1 < i2 < ... < ik`) to **maximize total watched time**: \[ \text{maximize } \sum_{t=1}^{k} d[i_t] \] subject to the constraint that **any two consecutively watched videos** do not exceed the attention span when added: \[ d[i_t] + d[i_{t+1}] \le A \quad \text{for all } t = 1..k-1 \] ### Task Write an algorithm/function that returns the **maximum total watched duration** achievable. ### Assumptions / clarifications - `n = len(d)` can be large enough that brute-forcing all subsets is too slow. - Watching 0 or 1 video is always allowed. ### Follow-up If the user is allowed to **watch the same video multiple times**, how would you modify the approach? - To avoid an unbounded/infinite answer, assume there is an additional limit `K` = maximum number of videos the user can watch total (including repeats). Return the maximum total watched duration under the same consecutive-sum constraint.

Quick Answer: This question evaluates algorithmic problem-solving in sequence optimization and constraint-based selection, testing competencies such as dynamic programming, subsequence selection, and handling pairwise adjacency constraints.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Jan 17, 2026, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
5
0

You have a list of videos in a feed. Video i has duration d[i] (positive integer). A user has an “attention span” limit A.

You want to select a subset of videos to watch (keeping the original order, i.e., choose a subsequence of indices i1 < i2 < ... < ik) to maximize total watched time:

maximize ∑t=1kd[it]\text{maximize } \sum_{t=1}^{k} d[i_t]maximize ∑t=1k​d[it​]

subject to the constraint that any two consecutively watched videos do not exceed the attention span when added:

d[it]+d[it+1]≤Afor all t=1..k−1d[i_t] + d[i_{t+1}] \le A \quad \text{for all } t = 1..k-1d[it​]+d[it+1​]≤Afor all t=1..k−1

Task

Write an algorithm/function that returns the maximum total watched duration achievable.

Assumptions / clarifications

  • n = len(d) can be large enough that brute-forcing all subsets is too slow.
  • Watching 0 or 1 video is always allowed.

Follow-up

If the user is allowed to watch the same video multiple times, how would you modify the approach?

  • To avoid an unbounded/infinite answer, assume there is an additional limit K = maximum number of videos the user can watch total (including repeats). Return the maximum total watched duration under the same consecutive-sum constraint.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Data Scientist•TikTok Data Scientist•TikTok Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.