InferenceAI

Enter at least two characters to search.

Start free

Anagram Start Positions

mediumSliding Window25 min25 XP

Return, in ascending order, every start index in s where a substring is an anagram of p.

Examples

EXAMPLE WALKTHROUGHtwo places

A guided view of the published example, not a trace of your code.

INPUT["cbaebabacd","abc"]
TASKanagram_start_positions()
EXPECTED OUTPUT[0,6]

Start with the input values shown in this example.

Example 1 of 3

Input: s = "cbaebabacd", p = "abc"

Output: [0,6]

Explanation: two places

Input: s = "abab", p = "ab"

Output: [0,1,2]

Explanation: overlapping

Input: s = "a", p = "ab"

Output: []

Explanation: pattern longer

Hint 1

Slide a window of length len(p) and compare letter counts in O(1) per step.

Topics

DSASliding WindowPython