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
Coding & Algorithms
Software Engineer
Karat
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
winnowing
rolling hash
Jaccard similarity
normalization
plagiarism detection
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions