FastPrepGroup Words by Their Letters
Problems/Group Words by Their Letters

Group Words by Their Letters

Adobe logoAdobe● MediumINTERNFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem puts words into groups of anagrams (same letters, same counts) and returns the groups in a fixed order. An Adobe web developer intern entry (a Taro copy of a Glassdoor review) lists, among the JavaScript tasks of its live technical interview (held online, on JavaScript and React), putting words that are anagrams of each other into groups, with a three-word example; it gives no output order, limits or rule for repeated words.

Our choices: groups in order of first appearance, words in input order inside each group, repeated words kept, lowercase words of 1 to 10 letters, at most 1500 words, any of five languages instead of JavaScript only, and new examples.

The judged task matches the report at about 85%.

Two words are anagrams when one is a rearrangement of the other: they use the same letters, each the same number of times. Put the words of words into groups so that each group holds all the words that are anagrams of each other.

Return the groups in the order in which their first word appears in words. Inside a group, keep the words in input order, including repeated copies.

Function

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

Examples

Example 1

words = ["listen","stone","silent","notes","tinsel","onset","angel"]return = [["listen","silent","tinsel"],["stone","notes","onset"],["angel"]]

listen, silent and tinsel use the same six letters; stone, notes and onset share another five. angel matches nothing. Groups follow the order in which their first word appears.

Example 2

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. Having the same set of letters is not enough: the counts must match too.

Example 3

words = ["go","og","go"]return = [["go","og","go"]]

The same word may appear twice; every copy stays in the group, in input order.

Constraints

  • 1 <= words.length <= 1500
  • each word is 1 to 10 lowercase English letters; the same word may appear more than once

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public List<List<String>> groupAnagrams(String[] words) {
    // Write your code here.
}
Checking account…