Problems > Anagram Windows

Anagram Windows

Difficulty: 1500 3000 ms 128 MB

strings sliding-window

Count the substrings of T that are anagrams (permutations) of P.

Input: two lines: the text T, then the pattern P.

Output: the number of anagram occurrences.

Constraints:

  • 1 ≤ |T| ≤ 105
  • 1 ≤ |P| ≤ |T|
  • lowercase letters

Sample Tests

Input 1
abab
ab
Output 1
3
Input 2
aaa
aa
Output 2
2

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.