text and pattern. Find every position i where text has a stretch of length len(pattern) made of the same letters as pattern, each the same number of times (in other words, a rearrangement of pattern).
Return the 0-based start indices of all such stretches in any order. If there are none, return an empty list.text="tealate", pattern="eat" → [0, 4]
The windows of length 3 are "tea" (0), "eal", "ala", "lat", "ate" (4). Only "tea" and "ate" use exactly e, a and t.
text="zzzz", pattern="zz" → [0, 1, 2]
Windows may overlap: starts 0, 1 and 2 all match.
text="ab", pattern="abc" → []
The pattern is longer than the text, so no window fits.
len(text), len(pattern) ≤ 3·10⁴text="tealate", pattern="eat"
[0, 4]
Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.