Select Keyframes With a Maximum Gap to Maximize Total Score

Last updated: November 29, 2026

Quick Overview

Each frame of a drive log has a usefulness score that may be negative. Choose a non-empty subsequence of frames in order so that consecutive chosen frames are at most k indices apart, maximizing the total score.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Each frame of a drive log has a usefulness score that may be negative. Choose a non-empty subsequence of frames in order so that consecutive chosen frames are at most k indices apart, maximizing the total score.

Curating training and test data from long logs is core to Applied Intuition's data engine, and keyframe selection with coverage gaps is a natural variant. The interviewer expects a DP whose transition is a sliding window maximum and an O(n) solution with a monotonic deque.

What the Interviewer Expects
  • Define dp[i] as the best total of a selection ending at frame i
  • Write the transition dp[i] = score[i] + max(0, max dp over the last k)
  • Maintain the window maximum with a monotonic decreasing deque
  • Handle all-negative scores by requiring a non-empty choice
  • Reach O(n) time
Key Topics to Cover
monotonic deque
sliding window maximum
dynamic programming
data curation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you recover the chosen frame indices?
  • What if the first and last frames must be chosen?
  • What if there is also a minimum gap between chosen frames?
  • How would you process a stream without storing all dp values?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

scores is a non-empty list of ints, k at least 1. Gaps are measured in indices. Return the best total; with all negative scores the answer is the single largest score....

High-Level Design

Let dp[i]=si+max⁡(0,max⁡i−k≤j<idp[j])dp[i] = s_i + \max(0, \max_{i-k \le j < i} dp[j]): either frame i starts a new selection or it extends the best selection ending in the window. A naive window scan is O(nk)O(nk). A deque of indices...


Submit Your Answer
Markdown supported

Related Questions