Traverse a Thumbnail Contact Sheet in Spiral Order
Last updated: November 29, 2026
Quick Overview
A video's preview contact sheet is an R by C grid of thumbnail frame ids. Return the ids in clockwise spiral order starting from the top-left, which the editor uses for an animated 'reveal' effect.
TikTok
November 29, 20260
0
0 solved
A video's preview contact sheet is an R by C grid of thumbnail frame ids. Return the ids in clockwise spiral order starting from the top-left, which the editor uses for an animated 'reveal' effect.
Matrix traversal is a staple of TikTok online assessments, here tied to CapCut style editing effects. The grader checks boundary bookkeeping on non-square grids, especially single rows and columns where naive code emits duplicates.
What the Interviewer Expects
- Uses four shrinking boundaries rather than a visited matrix
- Guards the bottom and left passes for single-row and single-column layers
- Works for non-square grids
- Handles an empty grid
- Tests degenerate shapes explicitly
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
- Return the order for a counter-clockwise spiral starting at the center.
- Generate the grid given n frames filled in spiral order.
- Can you do it as a generator without building the full list?
- How would you test this exhaustively for small shapes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of R rows each of C ids, possibly empty. Output: all R * C ids, each once, in clockwise spiral order from the top-left. Non-square grids are allowed....
High-Level Design
Keep four boundaries: top, bottom, left, right. Each loop peels one layer: the top row left to right, the right column top to bottom (skipping the corner already taken), the bottom row right t...