FunctionRacerProblemsRace

Find All Anagrams in a String

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

Return the start index of every contiguous piece of s that is an anagram of p (it has the same letters as p in any order). Give the indices in increasing order. Overlapping pieces all count, and if none exist return an empty list.

Example 1

s "cbaebabacd"
p "abc"
returns [0,6]

Pieces cba at 0 and bac at 6.

Example 2

s "abab"
p "ab"
returns [0,1,2]

Starts 0, 1 and 2 all work.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems