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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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 : either frame i starts a new selection or it extends the best selection ending in the window. A naive window scan is . A deque of indices...
Submit Your Answer
Applied Intuition Software Engineer Interview Guide
Interview process, tips, and preparation timeline