Problem · Array
Filter Anagrams of a Target
Learn this problemProblem statement
Given an array of lowercase strings words and a lowercase string target, return every entry of words that is an anagram of target.
Two strings are anagrams when they contain exactly the same letters with the same frequencies. Preserve the original order of matching entries, and preserve duplicate entries.
Function
filterTargetAnagrams(words: String[], target: String) → String[]Examples
Example 1
words = ["eat","tea","tan","ate","nat","bat"]target = "aet"return = ["eat","tea","ate"]eat, tea, and ate have the same letter frequencies as aet. They remain in their input order.
Example 2
words = ["abc","abb","bca","abc"]target = "cab"return = ["abc","bca","abc"]Both copies of abc and the entry bca match. The nonmatching entry abb is omitted.
Constraints
1 <= words.length <= 10^51 <= target.length <= 10^5- The total length of all strings in
wordsis at most2 * 10^5. - Every string contains only lowercase English letters.