Medium · Sliding Window

Find Anagram Substring Indices

Given strings s and p of lowercase letters, return, in increasing order, every index i such that the substring of s of length |p| starting at i is an anagram of p (the same letters with the same counts); return an empty list if there is none.

Examples

Example 1

s="cbaebabacd", p="abc"

Output: starts [0,6]

Example 2

s="abab", p="ab"

Output: starts [0,1,2]

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Sliding Window problems