You are given a string s and an array of strings words. All the strings of words are of the same length. A concatenated string is a string that exactly contains all the strings of any permutation of words concatenated. - For example, if words = ["ab","cd","ef"], then "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", and "efcdab" are all concatenated strings. "acdbef" is not because it is not the concatenation of any permutation of words. Return an array of the starting indices of all the concatenated substrings in s. You can return the answer in any order.
Example 1
Input: s = barfoothefoobarman, words = ["foo","bar"]
Output: [0,9]
Explanation: "barfoo" starting at index 0 and "foobar" starting at index 9 each use "foo" and "bar" exactly once. No other window of length 6 does.
Example 2
Input: s = wordgoodgoodgoodbestword, words = ["word","good","best","word"]
Output: []
Explanation: The words need "word" twice plus "good" and "best" (16 characters). No 16-character window of s contains exactly that mix, so there are no answers.
Example 3
Input: s = barfoofoobarthefoobarman, words = ["bar","foo","the"]
Output: [6,9,12]
Explanation: The windows at indices 6 ("foobarthe"), 9 ("barthefoo") and 12 ("thefoobar") each use "bar", "foo" and "the" exactly once.
Every word has the same length L, so a valid substring is a sequence of whole L-length chunks. Run a sliding window in chunk steps for each of the L possible starting offsets, keeping a running count of how many needed words are currently matched.
Run checks all cases above. Submit evaluates all test cases.