FastPrepDynamic Largest Anagram Group
Problems/Dynamic Largest Anagram Group

Dynamic Largest Anagram Group

Coupang logoCoupang● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Coupang phone screen. The report keeps the task of grouping anagrams as words come and go, with add, remove, and largest-group operations, and a follow-up comparing a write-optimized design with a read-optimized one. We added a finite batch interface, how repeated words work, a rule for removing a missing word, how ties are ordered, character limits, examples, and how the returned rows are written. We added them only to make the reported task runnable. Our version is about 75% the same as the reported question.

Design a collection of words that supports three operations:

  • ["add", word] adds one occurrence of word.
  • ["remove", word] removes one occurrence of word when it is present. Removing an absent word does nothing.
  • ["largestGroup"] reports the largest current group of mutually anagrammatic words.

You are given the operations in order as operations. Return one row for each largestGroup operation, in query order.

A group's size counts occurrences, so duplicate words are retained. Sort the words inside every returned group in lexicographic order. If several groups have the same maximum size, return the group whose sorted-letter anagram signature is lexicographically smallest. Return an empty row when the collection is empty.

Your design should make the trade-off between update work and query work explicit: workloads with frequent queries may maintain an ordered group index, while workloads with rare queries may scan the groups on demand.

Function

largestAnagramGroups(operations: String[][]) → String[][]

Examples

Example 1

operations = [["add","eat"],["add","tea"],["add","tan"],["largestGroup"],["remove","eat"],["largestGroup"]]return = [["eat","tea"],["tea"]]

eat and tea share one signature. After one eat is removed, the remaining group contains only tea.

Example 2

operations = [["add","ab"],["add","ba"],["add","ab"],["add","act"],["add","cat"],["largestGroup"],["remove","ab"],["largestGroup"]]return = [["ab","ab","ba"],["ab","ba"]]

Occurrences are counted independently. After one copy of ab is removed, signatures ab and act both have size two, so the lexicographically smaller signature ab wins.

Example 3

operations = [["largestGroup"],["remove","ghost"],["add","listen"],["add","silent"],["largestGroup"]]return = [[],["listen","silent"]]

The first query sees an empty collection. Removing an absent word is a no-op; the final two words are anagrams.

Constraints

  • 1 <= operations.length <= 100000.
  • Every row is exactly ["largestGroup"], ["add", word], or ["remove", word].
  • Every word contains only lowercase English letters and has length from 1 through 50.
  • The total number of characters across all operation words is at most 1000000.
  • The total number of words across all returned groups is at most 200000.

More Coupang Phone Screen questions

  • LRU CachePHONE SCREEN · Seen Oct 2026
  • Possible BipartitionPHONE SCREEN · Seen Jul 2020

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Log Analyzer: Busiest Service in a Rolling WindowByteDance · PHONE SCREENByteDance interview questions
  • User Journey PathsWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesStripe · PHONE SCREENStripe interview questions
  • Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
  • Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
See Coupang hiring insights
Saved
class Solution {
    public String[][] largestAnagramGroups(String[][] operations) {
        // write your code here
    }
}
Checking account…