A rearrangement inside a string
You get two strings of lowercase letters, pattern and text. A rearrangement of pattern uses exactly the same letters, each the same number of times, in any order: "eat", "tae" and "tea" itself are all rearrangements of "tea".
Return True if some block of len(pattern) consecutive letters in text is a rearrangement of pattern. Otherwise return False. If pattern is longer than text, no block fits, so the answer is False.
pattern = "tea", text = "seat"OutputTrueThe block "eat" has one e, one a and one t, the same letters as "tea".
pattern = "tea", text = "taxes"OutputFalseThe text has a t, an a and an e, but the blocks of 3 are "tax", "axe" and "xes", and each one misses at least one of them.
pattern = "aab", text = "abbab"OutputFalseCounts matter, not only which letters appear: every block of 3 holds only one a.
1 ≤ len(pattern) ≤ 105
1 ≤ len(text) ≤ 105
Both strings hold only lowercase letters a to z.
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.