Filter Anagrams of a Target
Updated
Problem 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.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
- Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
- Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Most Voted CandidateExpedia · ONSITE INTERVIEWExpedia interview questions
- List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions