Practice/Amazon/Leetcode 438. Find All Anagrams in a String
CodingMust
You are given two strings: text and pattern. Your task is to find all starting indices in text where a substring matches pattern as an anagram. Two strings are anagrams if they contain the same characters with the same frequencies, regardless of order.
Return a list of all starting positions (indices) in text where an anagram of pattern begins. The indices should be returned in ascending order.
text where a substring of length equal to pattern is an anagram of patterntext, pattern ≤ 30,000pattern is longer than texttextExample 1:
` Input: text = "cbaebabacd", pattern = "abc" Output: [0, 6] Explanation:
Example 2:
` Input: text = "abab", pattern = "ab" Output: [0, 1, 2] Explanation:
Example 3:
Input: text = "abcdef", pattern = "xyz" Output: [] Explanation: No substring of "abcdef" contains all the letters in "xyz"