FastPrepAnagram Words in a Sentence
Problems/Anagram Words in a Sentence

Anagram Words in a Sentence

Nutanix logoNutanix● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in the first of three interview rounds held on the same day for a Nutanix intern role. You get a sentence and find which of its words are anagrams of each other.

The report gives only that one-line task, with no examples, limits or output format. Here the sentence uses lowercase letters and single spaces and is at most 10^4 characters long. You return the anagram words in groups of two or more. A repeated word counts once and does not pair with itself. Words in a group, and the groups themselves, follow the order in which the words first appear.

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

You are given a string sentence made of words separated by single spaces. Each word is made of lowercase English letters.

Two different words are anagrams of each other if one can be turned into the other by reordering its letters. In other words, they use exactly the same letters, the same number of times each. For example, stop and pots are anagrams, but aab and abb are not.

Find the words of the sentence that are anagrams of each other, and return them in groups:

  • Each group holds words that are all anagrams of one another, and it must contain at least two different words. A word with no anagram in the sentence is left out.
  • A word that appears more than once is listed only once. A word is not an anagram of itself, so repeating a word does not make a group.
  • Inside a group, list the words in the order of their first appearance in the sentence.
  • Order the groups by where their first word first appears in the sentence.

If no two different words are anagrams, return an empty list.

Function

findAnagramGroups(sentence: String) → List<List<String>>

Examples

Example 1

sentence = "the night shift thing pots stop tops ends here"return = [["night","thing"],["pots","stop","tops"]]

night and thing both use the letters g, h, i, n, t once each, so they form a group. pots, stop and tops all use o, p, s, t once each, so they form a second group, listed in the order they appear.

The other words (the, shift, ends, here) have no partner. The group with night comes first because night appears before pots.

Example 2

sentence = "listen to the silent stone notes as onset enlist"return = [["listen","silent","enlist"],["stone","notes","onset"]]

listen, silent and enlist all use e, i, l, n, s, t once each. stone, notes and onset all use e, n, o, s, t once each.

to, the and as have no partner. listen is the first word of the sentence, so its group comes first.

Example 3

sentence = "we saw a cat and a dog"return = []

No two different words here use the same letters. The word a appears twice, but a word is not an anagram of itself, so the two copies do not form a group. The answer is an empty list.

Constraints

  • 1 <= sentence.length <= 10^4
  • sentence contains only lowercase English letters and spaces.
  • Words are separated by exactly one space, and there is no space at the start or end.

More Nutanix Onsite Interview questions

  • Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
  • Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
  • Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 2026
  • Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
  • LRU CacheONSITE INTERVIEW · Seen Aug 2025
  • Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
  • Custom Array IteratorONSITE INTERVIEW · Seen Dec 2024
  • Collapse Runs of Repeated CharactersONSITE INTERVIEW · Seen Nov 2022
  • Sudoku SolverONSITE INTERVIEW · Seen Feb 2022
  • Distance Sums to Special Nodes in a Weighted TreeONSITE INTERVIEW · Seen Aug 2021

Similar questions at other companies

  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Check AnagramsDeloitte · ONSITE INTERVIEWDeloitte interview questions
  • Check AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Check Anagram Pairs Index by IndexExpedia · ONSITE INTERVIEWExpedia interview questions
  • Recursive Character FrequencyPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
  • Valid AnagramMotive · ONSITE INTERVIEWMotive interview questions
  • List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions

Interview reports that mention this question

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)

Nutanix interview experiences

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public List<List<String>> findAnagramGroups(String sentence) {
        // Write your code here.
    }
}
Checking account…