PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Millennium

Design a data structure to store anagrams

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in data structures and algorithms for string grouping and lookup, testing skills in string manipulation, canonicalization/hashing concepts, memory-time trade-offs, and handling duplicates.

  • medium
  • Millennium
  • Coding & Algorithms
  • Software Engineer

Design a data structure to store anagrams

Company: Millennium

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are building a small in-memory service that stores words and can return all stored words that are anagrams of a query. Design and implement a data structure **AnagramStore** supporting the following operations: 1. `add(word: string) -> void`: Add a word to the store (duplicates may exist). 2. `getAnagrams(query: string) -> list<string>`: Return **all** words previously added that are anagrams of `query` (including the word itself if it was added). The order of the returned list does not matter. Two words are anagrams if they contain the same letters with the same frequencies (case-insensitive; assume input is lowercase `a-z` unless you state otherwise). ### Example - Add: `"eat"`, `"tea"`, `"tan"`, `"ate"`, `"nat"`, `"bat"` - `getAnagrams("ate")` can return: `["eat", "tea", "ate"]` - `getAnagrams("ant")` can return: `["tan", "nat"]` - `getAnagrams("tab")` can return: `["bat"]` ### Constraints (you may assume) - Up to `10^5` total `add` operations - Word length up to `100` ### Requirements - Explain the time and space complexity of your approach. - Discuss how you would handle duplicates (e.g., adding the same word multiple times).

Quick Answer: This question evaluates proficiency in data structures and algorithms for string grouping and lookup, testing skills in string manipulation, canonicalization/hashing concepts, memory-time trade-offs, and handling duplicates.

Millennium logo
Millennium
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0
Loading...

Problem

You are building a small in-memory service that stores words and can return all stored words that are anagrams of a query.

Design and implement a data structure AnagramStore supporting the following operations:

  1. add(word: string) -> void : Add a word to the store (duplicates may exist).
  2. getAnagrams(query: string) -> list<string> : Return all words previously added that are anagrams of query (including the word itself if it was added). The order of the returned list does not matter.

Two words are anagrams if they contain the same letters with the same frequencies (case-insensitive; assume input is lowercase a-z unless you state otherwise).

Example

  • Add: "eat" , "tea" , "tan" , "ate" , "nat" , "bat"
  • getAnagrams("ate") can return: ["eat", "tea", "ate"]
  • getAnagrams("ant") can return: ["tan", "nat"]
  • getAnagrams("tab") can return: ["bat"]

Constraints (you may assume)

  • Up to 10^5 total add operations
  • Word length up to 100

Requirements

  • Explain the time and space complexity of your approach.
  • Discuss how you would handle duplicates (e.g., adding the same word multiple times).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Millennium•More Software Engineer•Millennium Software Engineer•Millennium Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.