228. Find All Anagrams in a String (Count)

MediumStringString

Given strings s and p, return the number of start indices in s where an anagram of p begins. Input: '"s", "p"'.

Input: '"s", "p"'.

Output: Integer — number of anagram occurrences.

Examples

Example 1
Input: "cbaebabacd", "abc"
Output: 2
Explanation: Anagrams at indices 0 and 6.
Example 2
Input: "abab", "ab"
Output: 3
Explanation: Indices 0,1,2.
Example 3
Input: "a", "a"
Output: 1
Explanation: One match.

Constraints

Asked by

AmazonBloombergMicrosoftAccentureMetaGoogle
Solve this problem in the editor →