Group Near-Duplicate Prompts Before Shipping a Training Data Pack
Last updated: November 29, 2026
Quick Overview
Given a list of (prompt_id, text) pairs, return every group of two or more prompt IDs whose text is identical after lowercasing, trimming and collapsing runs of whitespace. Output the groups sorted so the result is deterministic.
Turing
November 29, 20260
0
0 solved
Given a list of (prompt_id, text) pairs, return every group of two or more prompt IDs whose text is identical after lowercasing, trimming and collapsing runs of whitespace. Output the groups sorted so the result is deterministic.
Turing delivers curated SFT and RLHF data packs to frontier labs, and duplicate prompts inflate counts and leak between train and eval splits. A warm-up like this checks that a candidate writes clean hashing code and thinks about normalization rules before an interviewer moves on to fuzzier deduplication.
What the Interviewer Expects
- Defines the normalization explicitly before coding
- Uses a hash map keyed by normalized text for O(total characters) work
- Returns only groups with at least two members
- Makes output order deterministic
- Mentions why exact match is not enough in production and what comes next
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 catch prompts that differ only by punctuation or variable names in code?
- How would you scale this to 200 million prompts that do not fit in memory?
- How would you dedupe across a new pack and every pack already delivered to the same client?
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 is a list of (prompt_id, text). Two prompts are duplicates when their texts match after: lowercasing, trimming the ends, and replacing any run of whitespace (spaces, tabs, newlines) with one s...
High-Level Design
Compute a canonical key per prompt and bucket IDs by key in a dictionary. Any bucket with more than one ID is a duplicate group. Sorting the IDs inside each group and then the groups themselves makes ...