Find all anagram start indices
Company: Databricks
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates proficiency in string manipulation, algorithmic efficiency, and pattern detection through character frequency analysis, assessing practical competency in handling fixed-length substring comparisons.
Constraints
- 1 <= len(s), len(p) <= 3 * 10^4
- s and p contain only lowercase English letters
- Indices must be returned in increasing order
Examples
Input: ("cbaebabacd", "abc")
Expected Output: [0, 6]
Explanation: The substrings "cba" at index 0 and "bac" at index 6 are both anagrams of "abc".
Input: ("abab", "ab")
Expected Output: [0, 1, 2]
Explanation: The windows "ab", "ba", and "ab" are all anagrams of "ab".
Input: ("aaaaa", "aa")
Expected Output: [0, 1, 2, 3]
Explanation: Every substring of length 2 is "aa", which is an anagram of "aa".
Input: ("abc", "abcd")
Expected Output: []
Explanation: p is longer than s, so no valid substring can exist.
Input: ("a", "a")
Expected Output: [0]
Explanation: The only substring is "a", which matches p exactly.
Input: ("xyz", "ab")
Expected Output: []
Explanation: No substring of length 2 in s has the same character counts as "ab".