Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Find All Anagrams in a String

Medium
sliding-windowstringhash-table

Given two strings s and p, return the start indices of all anagrams of p inside s, in increasing order.

Input

  • Line 1: string s
  • Line 2: string p

Output: the start indices, space-separated (nothing if none).

Example 1
Input:
cbaebabacd
abc
Output:
0 6

"cba" at 0 and "bac" at 6.

Example 2
Input:
abab
ab
Output:
0 1 2

Constraints

  • 1 ≤ s.length, p.length ≤ 3·10^4
  • Lowercase English letters only.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.