Flag Near Duplicate Code Submissions Using Winnowed Fingerprints
Last updated: November 29, 2026
Quick Overview
Given a set of candidate code submissions for the same question, normalize each one, compute winnowed k-gram fingerprints, and return all pairs whose fingerprint Jaccard similarity is at or above a threshold, robust to renamed variables and reformatting.
Karat
November 29, 20260
0
0 solved
Given a set of candidate code submissions for the same question, normalize each one, compute winnowed k-gram fingerprints, and return all pairs whose fingerprint Jaccard similarity is at or above a threshold, robust to renamed variables and reformatting.
Interview integrity matters to a company whose scores feed hiring decisions at many clients, and shared questions invite copied answers. The interviewer checks whether you know a document fingerprinting technique, can implement the window selection correctly, and can reason about false positives.
What the Interviewer Expects
- Normalize away identifiers, comments, strings, and whitespace
- Hash every k-gram with a stable hash function
- Select the minimum hash in each window of size w, deduplicating positions
- Compare fingerprint sets with Jaccard similarity
- Discuss why short canonical solutions cause false positives
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
- Pairwise comparison is quadratic. How do you scale to a million submissions?
- How do you choose k and w, and what guarantee does winnowing give?
- How would you exclude the starter template every candidate receives?
- Would you ever auto-reject on this score? What process should follow a flag?
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 {submission_id: code}. Output (a, b, score) pairs with score at least threshold, sorted by score. Must be insensitive to renaming and whitespace. Hashes must be stable across processes, so...
High-Level Design
Normalize: strip comments, collapse string literals, replace every identifier and keyword with v, remove whitespace. Take all k-grams and hash them. Winnowing slides a window of w consecutive hashes...