Maximize watch time under adjacency constraint
Problem Description
You are given a sequence of videos in a feed.
-
Input:
- An integer array
durationof lengthn, whereduration[i]represents the length of videoiin seconds. - An integer
A, representing the user’s attention limit.
- An integer array
-
Task:
- Select a subsequence of videos from the original feed. The selected videos must maintain their original relative order. Let this selected subsequence be
i1 < i2 < ... < ik. - Constraint: For every adjacent pair of videos in the selected subsequence (
duration[ij]andduration[ij+1]), their combined duration must not exceed the user's attention limitA. That is,duration[ij] + duration[ij+1] <= A. - Objective: Maximize the total watch time, which is the sum of the durations of all selected videos:
sum(duration[ij]).
- Select a subsequence of videos from the original feed. The selected videos must maintain their original relative order. Let this selected subsequence be
-
Output:
- Return the maximum achievable total watch time.
Follow-up
Suppose the user is allowed to rewatch the same video multiple times, and the session must consist of exactly m selections. How would you modify your approach to compute the maximum total watch time under the same adjacency constraint?
AI interview prep
Core dilemma
Optimizing a global sum by making sequential, constrained choices, where each choice impacts future possibilities, without violating pairwise adjacency limits. The core challenge is efficiently exploring the state space while adhering to the 'original order' and 'adjacency' constraints.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Maximize watch time under adjacency constraint
Problem Description
You are given a sequence of videos in a feed.
-
Input:
- An integer array
durationof lengthn, whereduration[i]represents the length of videoiin seconds. - An integer
A, representing the user’s attention limit.
- An integer array
-
Task:
- Select a subsequence of videos from the original feed. The selected videos must maintain their original relative order. Let this selected subsequence be
i1 < i2 < ... < ik. - Constraint: For every adjacent pair of videos in the selected subsequence (
duration[ij]andduration[ij+1]), their combined duration must not exceed the user's attention limitA. That is,duration[ij] + duration[ij+1] <= A. - Objective: Maximize the total watch time, which is the sum of the durations of all selected videos:
sum(duration[ij]).
- Select a subsequence of videos from the original feed. The selected videos must maintain their original relative order. Let this selected subsequence be
-
Output:
- Return the maximum achievable total watch time.
Follow-up
Suppose the user is allowed to rewatch the same video multiple times, and the session must consist of exactly m selections. How would you modify your approach to compute the maximum total watch time under the same adjacency constraint?