Group Duplicate User Prompts After Text Normalization

Last updated: November 29, 2026

Quick Overview

Given a list of raw prompts, group the indices of prompts that are identical after lowercasing, removing punctuation and collapsing whitespace, returning only groups with at least two members ordered by first occurrence.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of raw prompts, group the indices of prompts that are identical after lowercasing, removing punctuation and collapsing whitespace, returning only groups with at least two members ordered by first occurrence.

Deduplicating prompts shows up across OpenAI's work, from cleaning evaluation sets so a model is not scored twice on the same item to caching identical API requests. The phone screen version checks that you choose a good canonical key, use a hash map correctly, and produce deterministic output ordering.

What the Interviewer Expects
  • Define the normalization precisely before coding
  • Use a dictionary keyed by the normalized string
  • Return deterministic ordering of groups and of indices within groups
  • Run in linear time in total input size
  • Discuss how normalization choices change what counts as duplicate
Key Topics to Cover
hash map
string normalization
grouping
deduplication
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
  • How would you find near-duplicates that differ by a word or two?
  • The prompt list is 2 billion rows across many machines: how do you group them?
  • What if two prompts should match when they differ only in Unicode forms like full-width characters?
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: a list of prompt strings. Output: a list of index lists.
  • Two prompts are duplicates if their normalized forms are equal.
  • Normalization: lowercase, drop punctuation, collapse runs of white...
High-Level Design

Compute a canonical key per prompt and bucket indices by key in a dictionary. Because we iterate in index order, each bucket's list is already sorted. At the end, filter buckets with more than one ind...


Submit Your Answer
Markdown supported