 All Problems
Find All Anagrams in a String
medium
sliding window
hash map
strings
facebook
amazon

Given strings s and p, return all start indices of anagrams of p in s.

Example 1:

Input:
cbaebabacd
abc
Output: 0 6

Example 2:

Input:
abab
ab
Output: 0 1 2

Constraints:

  • 1 ≤ s.length, p.length ≤ 3 × 10⁴
  • s and p consist of lowercase English letters

Input format: First line: s. Second line: p.

Output format: Space-separated start indices.

Run to check your code against the sample cases, or submit to run every case