Find All Anagrams in a String

Medium
StringSliding WindowHash TableAmazonGoogle
Given strings s and p, print every start index where a substring of s is an anagram of p. Input format: - First line: s - Second line: p Print indices in increasing order on one line separated by spaces. Print `EMPTY` if there are none.

Constraints

1 <= p.length <= s.length <= 2 * 10^5
Strings contain lowercase English letters.

Sample tests

Sample 1

Sample 2

Sign in to submit