Anagram Finder

Hashmap String Manipulation Sliding Window

Problem Description

You are given two strings, s and p. Your task is to find all the starting indices of p's anagrams in s.

An anagram is a rearrangement of characters. For example, the anagrams of "abc" include "abc", "acb", "bac", "bca", "cab", and "cba".

Input

  • A string s.
  • A string p.

Output

  • An array (or list) of starting indices of p's anagrams in s. The order of indices in the result does not matter.

Example

Input: s = "cbaebabacd", p = "abc"
Output: [0, 6]
Explanation:
The substring starting at index 0 is "cba" which is an anagram of "abc".
The substring starting at index 6 is "bac" which is an anagram of "abc".

Notes

  • This problem requires utilization of hashmaps to track character frequencies efficiently.
  • As today is January 21, a day that often reminds us of historical innovations, let your solution be both innovative and efficient!