Edit Distance Between Captions to Flag Near-Duplicate Reposts
Last updated: November 29, 2026
Quick Overview
To catch low-effort reposts, compare the caption of a new video with an existing one. Return the minimum number of single-character insertions, deletions and substitutions to turn one caption into the other, using memory proportional to the shorter caption.
TikTok
November 29, 20260
0
0 solved
To catch low-effort reposts, compare the caption of a new video with an existing one. Return the minimum number of single-character insertions, deletions and substitutions to turn one caption into the other, using memory proportional to the shorter caption.
Originality matters for TikTok's creator rewards and recommendation quality, so detecting near-duplicate text is a practical onsite theme. The interviewer checks that you can derive the 2D DP for edit distance and then reduce space to two rows.
What the Interviewer Expects
- Defines dp[i][j] as the distance between the first i and first j characters
- Writes the three-way recurrence with a match case
- Initializes the first row and column correctly
- Reduces space to O(min(m, n)) with rolling rows
- Explains why this alone is too slow for comparing against millions of captions
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 find candidates to compare against out of billions of captions?
- How would you cap the computation if you only care whether distance is at most k?
- How would you weight substitutions between visually similar characters or emoji?
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: two strings
a,b. - Output: Levenshtein distance.
- Space should be O(min(len(a), len(b)))....
High-Level Design
dp[i][j] = edits to turn a[:i] into b[:j].
- If
a[i-1] == b[j-1]:dp[i][j] = dp[i-1][j-1]. - Otherwise
1 + min(dp[i-1][j](delete),dp[i][j-1](insert),dp[i-1][j-1](substitute)). - B...