FastPrepWords with Repeated Anagrams

Words with Repeated Anagrams

The Voleon Group logoThe Voleon Group● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an array of lowercase words, return every input word whose letters can be rearranged to form at least one other word at a different input index.

Preserve the original input order and occurrences. Equal strings at different indices count as anagram partners.

Function

wordsWithRepeatedAnagrams(words: String[]) → String[]

Examples

Example 1

words = ["listen","silent","cat","tac","dog"]return = ["listen","silent","cat","tac"]

The first two and middle two words form repeated anagram groups.

Example 2

words = ["aa","aa","b"]return = ["aa","aa"]

Equal occurrences at different indices are partners.

Constraints

  • 0 <= words.length <= 100000.
  • 1 <= words[i].length <= 100.
  • Words contain lowercase English letters.

More The Voleon Group problems

See The Voleon Group hiring insights
public String[] wordsWithRepeatedAnagrams(String[] words) {
    // Write your solution here.
}
words["listen","silent","cat","tac","dog"]
expected["listen", "silent", "cat", "tac"]
Checking account…