FastPrepGroup Anagram Strings
Problems/Group Anagram Strings

Group Anagram Strings

London Stock Exchange logoLondon Stock Exchange● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names grouping anagrams but does not give the full statement, the alphabet, or the order. We chose those. Our version is about 85% the same as the reported question.

Group the strings in words so that two strings belong to the same group exactly when they contain the same letters with the same counts. These strings are anagrams.

Keep every occurrence, including duplicates and empty strings. Sort the strings within each group lexicographically, then sort the groups lexicographically by their first string. Return the resulting groups. For an empty input, return an empty list.

Function

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

Examples

Example 1

words = ["eat","tea","tan","ate","nat","bat"]return = [["ate","eat","tea"],["bat"],["nat","tan"]]

The groups are ["ate","eat","tea"], ["bat"], and ["nat","tan"]. Their first strings determine the returned group order.

Example 2

words = ["",""]return = [["",""]]

Both empty strings have zero of every letter and stay in one group.

Example 3

words = []return = []

No string needs a group, so the result is empty.

Constraints

  • 0 <= words.length <= 2000.
  • Each word has length from 0 through 50.
  • Every character is a lowercase English letter.

More London Stock Exchange interview questions

  • Implement Key Equality and HashingONSITE INTERVIEW · Seen Apr 2020
  • Implement a Queue Using an ArrayPHONE SCREEN · Seen Feb 2020
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Feb 2020
  • Palindrome PartitioningPHONE SCREEN · Seen Feb 2020
  • Two SumPHONE SCREEN · Seen Feb 2020
  • Two Sum in a Sorted ArrayPHONE SCREEN · Seen Feb 2020

Similar questions at other companies

  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
  • Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Group AnagramsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Group AnagramsAkuna Capital · ONSITE INTERVIEWAkuna Capital interview questions
All London Stock Exchange interview questionsSee London Stock Exchange hiring insights
Saved
class Solution {
    public List<List<String>> groupAnagrams(String[] words) {
        // Write your solution here.
    }

}
Checking account…