You are given a string
s and an array of strings
words of the same length. Return all starting indices of substring(s) in
s that is a concatenation of each word in
words exactly once, in any order, and without any intervening characters.
You can return the answer in any order.
Input: s = "barfoothefoobarman", words = ["foo","bar"] Output: [0,9] Explanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively. The output order does not matter, returning [9,0] is fine too.
Input: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"] Output: 
Input: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"] Output: [6,9,12]
1 <= s.length <= 104
sconsists of lower-case English letters.
1 <= words.length <= 5000
1 <= words[i].length <= 30
words[i]consists of lower-case English letters.
This question requires the knowledge of sliding window approach. If we keep track of what are the words available in the word list along with it's count and use them one by one, then by sliding window technique we can easily solve this question. A detailed analysis is provided in the Video.
Time Complexity: O(n*(l*m)) // where n is the length of string and l is the number of words in wordlist and m is the length of each word.
Space Complexity: O(l*m) // where l is the number of words in the wordlist and m is the length of each word.