Basic example
Input
s = 'cbaebabacd', p = 'abc'
Output
[0, 6]
Substrings 'cba' at index 0 and 'bac' at index 6 are anagrams of 'abc'.
Full lesson preview
Return start indices of all anagrams of a pattern inside a string using a sliding window.
Problem statement
Task
Examples
Input
s = 'cbaebabacd', p = 'abc'
Output
[0, 6]
Substrings 'cba' at index 0 and 'bac' at index 6 are anagrams of 'abc'.
Input format
Output format
Constraints
Samples
Input
s = 'abab', p = 'ab'
Output
[0, 1, 2]
All substrings starting at 0,1,2 are anagrams of 'ab'.