Quick Overview

Return all input occurrences belonging to repeated anagram groups, preserving order and duplicates with multiplicity-aware letter-count signatures.

Return Words in Repeated Anagram Groups

Company: Voleon

Role: Quantitative Researcher

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given a list of words, return every word whose anagram signature occurs more than once in the list. A signature records how many times each letter occurs, regardless of letter order. Implement `repeated_anagram_words(words: string[]) -> string[]`. ### Constraints & Assumptions - At most 100000 words and at most 1000000 letters in total. Words contain lowercase ASCII letters only; empty words are allowed. - Return qualifying occurrences in their original input order. Do not sort words or deduplicate the output. - Identical repeated words count as multiple occurrences of their signature. Two empty words also share a repeated signature. - A signature must preserve multiplicity: `ab` and `aab` are different. - Aim for O(total letters + number of words) time using a fixed-size letter-count signature per word. ### Examples ```text words = ["eat","tea","bat","eat","tan","nat","solo"] result = ["eat","tea","eat","tan","nat"] ``` ```text words = ["a","ab","aab",""] result = [] ``` The output order and duplicate policy are explicit practice conventions where the source leaves them unspecified. Explain why a set of distinct letters is insufficient and how a count-signature avoids sorting every word. ```hint Count signatures before selecting occurrences Whether the first word qualifies may depend on a later word. Keep the original ordering separate from the signature frequency table. ```

Overview: Return all input occurrences belonging to repeated anagram groups, preserving order and duplicates with multiplicity-aware letter-count signatures.

Read the full Voleon Quantitative Researcher interview experience this question came from

Given a list of words, return every word whose anagram signature occurs more than once in the list. A signature records how many times each letter occurs, regardless of letter order. Implement `repeated_anagram_words(words: string[]) -> string[]`. ### Constraints & Assumptions - At most 100000 words and at most 1000000 letters in total. Words contain lowercase ASCII letters only; empty words are allowed. - Return qualifying occurrences in their original input order. Do not sort words or deduplicate the output. - Identical repeated words count as multiple occurrences of their signature. Two empty words also share a repeated signature. - A signature must preserve multiplicity: `ab` and `aab` are different. - Aim for O(total letters + number of words) time using a fixed-size letter-count signature per word. ### Examples ```text words = ["eat","tea","bat","eat","tan","nat","solo"] result = ["eat","tea","eat","tan","nat"] ``` ```text words = ["a","ab","aab",""] result = [] ``` The output order and duplicate policy are explicit practice conventions where the source leaves them unspecified. Explain why a set of distinct letters is insufficient and how a count-signature avoids sorting every word. ```hint Count signatures before selecting occurrences Whether the first word qualifies may depend on a later word. Keep the original ordering separate from the signature frequency table. ```

Constraints

  • At most 100000 lowercase ASCII words and 1000000 total letters; empty words are permitted.
  • A signature records the count of every letter and must preserve multiplicity.
  • Return every occurrence whose signature appears more than once, in original order without deduplication.
  • Identical words and repeated empty words count as repeated occurrences.

Examples

Input: (['eat', 'tea', 'bat', 'eat', 'tan', 'nat', 'solo'],)

Expected Output: ['eat', 'tea', 'eat', 'tan', 'nat']

Explanation: The source keeps every qualifying occurrence in original order.

Input: (['a', 'ab', 'aab', ''],)

Expected Output: []

Explanation: Same letter sets with different counts do not share a signature.

Loading coding console...

Show the approach

Approach

Represent a word by its 26 letter multiplicities. Equal count tuples are equivalent to being anagrams because order is irrelevant but every letter occurrence is preserved. A mere set of letters would wrongly merge ab with aab. First count signature frequencies over all occurrences, including duplicates and empty words. Then scan the original list again, emitting each word whose signature frequency exceeds one. This retains order and duplicate occurrences, and lets a later anagram qualify an earlier word. Recomputing signatures on the second scan avoids storing a separate key per input occurrence. With L total letters and N words, two fixed-alphabet counting passes take expected O(L+N) time. State stores one 26-count signature per distinct class plus frequencies and a temporary counter. Textual signatures in Java/JavaScript/C++ use separators to make the count encoding unambiguous; their character storage depends on count digit lengths. No word sorting is required.

Time complexity:
O(total letters + number of words) expected
Space complexity:
O(26 * distinct signatures) count information, plus encoded-key characters and output