Given two lowercase strings s and p, return every start index of a substring in s that is an anagram of p.
Return the indices in ascending order.
Input / output
s: string, p: stringint[] of start indicesExamples
s = "cbaebabacd", p = "abc" returns [0, 6].s = "abab", p = "ab" returns [0, 1, 2].s = "af", p = "be" returns [].Constraints
1 <= p.length <= s.length <= 30000s and p contain only lowercase English letters.Edge cases
p matter.Target complexity
O(|s|) time and O(1) extra space beyond the output.Hints
p.length, adding one new character and removing one old character each step.Follow-up
How would your approach change if s and p could contain arbitrary Unicode characters instead of only lowercase English letters?