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.
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:
subject to the constraint that any two consecutively watched videos do not exceed the attention span when added:
Write an algorithm/function that returns the maximum total watched duration achievable.
n = len(d)
can be large enough that brute-forcing all subsets is too slow.
If the user is allowed to watch the same video multiple times, how would you modify the approach?
K
= maximum number of videos the user can watch total (including repeats). Return the maximum total watched duration under the same consecutive-sum constraint.