Example with two matches
Input
s = 'cbaebabacd', p = 'abc'
Output
[0, 6]
The substring at index 0 'cba' and at index 6 'bac' are anagrams of 'abc'.
Full lesson preview
Find all start indices of p's anagrams in s using a sliding window and frequency counting.
Problem statement
Task
Examples
Input
s = 'cbaebabacd', p = 'abc'
Output
[0, 6]
The substring at index 0 'cba' and at index 6 'bac' are anagrams of 'abc'.
Input format
Output format
Constraints
Samples
Input
s = 'abab', p = 'ab'
Output
[0, 1, 2]
Windows 'ab','ba','ab' are all anagrams of 'ab'.