You're given a string s and an array of strings words, where all strings in words have the same length. Your task is to find all starting indices in s where a concatenated substring begins.
A concatenated substring is formed by joining all strings from words in any order, using each word exactly once. For example, if words = ["ab", "cd", "ef"], then valid concatenated strings include:
"abcdef","abefcd","cdabef""cdefab","efabcd","efcdab"
However, "acdbef" would not be valid because it doesn't represent any permutation of the original words.
Goal: Return an array of all starting indices where these concatenated substrings appear in s.
Input & Output
Visualization
Time & Space Complexity
We process each character at most a constant number of times across all sliding windows
Space for hash maps storing word frequencies and current window state
Constraints
- 1 โค s.length โค 104
- 1 โค words.length โค 5000
- 1 โค words[i].length โค 30
- All strings of words are the same length
- s and words[i] consist of lowercase English letters only