Separate a Sentence Into Anagram Groups
Updated
Problem statement
text is a list of lowercase words separated by single spaces. Two words belong together when one can be turned into the other by rearranging its letters, which means every letter appears the same number of times in both.
Return the groups of words that belong together. List the groups in the order their earliest word appears in text; inside a group, keep the order of text, repeated words included.
Function
separateAnagrams(text: String) → List<List<String>>Examples
Example 1
text = "ocean evil vile live canoe"return = [["ocean","canoe"],["evil","vile","live"]]ocean and canoe share the letters a, c, e, n, o, and evil, vile and live share theirs. The ocean group is listed first because its first word comes first in the text, even though the other group is bigger.
Example 2
text = "note tone note"return = [["note","tone","note"]]tone rearranges note, and the second note is kept as well, so the one group has three words.
Example 3
text = "aab abb ab"return = [["aab"],["abb"],["ab"]]All three words use only a and b, but in different amounts: two a's, two b's, or one of each. Different counts mean different groups.
Constraints
textholds between1and2000words separated by single spaces, with no leading or trailing space.- Each word has
1to10lowercase English letters.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
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
- Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
- Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
- Sort Characters by FrequencySnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences