#C6909. Permutation Subarray Count
Permutation Subarray Count
Permutation Subarray Count
Given a string s and a pattern p, your task is to count the number of subarrays of s (of length equal to the length of p) that are permutations of p. A subarray is a contiguous segment of the string, and two subarrays are considered different if they start at different positions, even if they contain the same sequence of characters.
The condition for a subarray s[i...i+|p|-1] to be a permutation of p is that the frequency counts of every character in both strings are identical. This can be formally written as:
$$ \text{match} \iff \forall\, c \in \Sigma, \quad \mathrm{count}(s[i\ldots i+|p|-1], c) = \mathrm{count}(p, c) $$Note that if the length of p is greater than the length of s, the answer is 0
.
inputFormat
The input consists of two lines. The first line contains the string s, and the second line contains the string p.
outputFormat
Output a single integer representing the number of subarrays of s that are permutations of p.## sample
cbabcacab
abc
4
</p>