This Coding & Algorithms question for a Data Engineer role evaluates dynamic programming and sequence-optimization skills by requiring selection of a subsequence under a pairwise adjacency constraint on video durations, at a moderate-to-advanced algorithmic abstraction level.
You are given a sequence of videos in a feed.
duration[1..n]
, where
duration[i]
is the length of video
i
in seconds.
A
(the user’s attention limit).
i1 < i2 < ... < ik
. The constraint is:
duration[ij] + duration[ij+1] <= A
.
sum(duration[ij])
.
Follow-up:
m
selections (so repetitions are allowed, but the number of watched items is capped). How would you modify your approach to compute the maximum total watch time under the same adjacency constraint?