FastPrepGroup Anagrams in First-Seen Order
Problems/Group Anagrams in First-Seen Order

Group Anagrams in First-Seen Order

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 report on a Google L5 ML SWE loop (later approved at L4) says the coding round's problem was a harder relative of Group Anagrams. The report gives no other detail.

It does not say what made it harder. This version is the plain grouping task that the report names as its base. Groups follow the order of their first word, words keep their input order, and repeats are kept. The limits are our choice.

Our version is about 35% the same as the reported question.

Two words are anagrams when one can be made by reordering the letters of the other, using every letter exactly as many times as it appears. Split words into groups so that two words share a group exactly when they are anagrams.

Return the groups in a fixed order:

  • List the groups in the order in which their first word appears in words.
  • Inside a group, keep the words in their input order.
  • Keep repeated words: a word that appears several times appears that many times in its group.

Function

groupAnagrams(words: String[]) → List<List<String>>

Examples

Example 1

words = ["stop","pots","tops","opts","spot","post","pot"]return = [["stop","pots","tops","opts","spot","post"],["pot"]]

The first six words use the letters o, p, s and t once each, so they form one group, in their input order. pot has no s, so it is alone.

Example 2

words = ["listen","enlist","google","silent","elgoog","listen"]return = [["listen","enlist","silent","listen"],["google","elgoog"]]

listen starts the first group, which also gets enlist, silent and the second listen. google starts the second group with elgoog. Groups are listed in the order of their first word.

Example 3

words = ["aab","abb","bab","baa"]return = [["aab","baa"],["abb","bab"]]

aab and baa have two a's and one b. abb and bab have one a and two b's. Using the same set of letters is not enough: the counts must match.

Constraints

  • 1 <= words.length <= 1000
  • Each words[i] has 1 to 10 lowercase English letters.

More Google Onsite Interview questions

  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Filesystem Entity Total SizeONSITE INTERVIEW · Seen Nov 2026
  • Longest Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
  • Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Most Frequent Call Stack Per ThreadRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Build an Inverted Document IndexConfluent · ONSITE INTERVIEWConfluent interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Sort Characters by FrequencySnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Top K Frequent WordsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions

Interview reports that mention this question

  • Google SWE III ML Experienced Hires: 34 Experiences (Part 1 of 4)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public List<List<String>> groupAnagrams(String[] words) {
        // Write your code here.
    }
}
Checking account…