human
I found an interesting problem on https://leetcode.com/problems/substring-with-concatenation-of-all-words/:
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.

Example 1:

Input:
s = "barfoothefoobarman",
words = ["foo","bar"]
Output: [0,9]
Explanation: Substrings starting at index 0 and 9 are "barfoor" and "foobar" respectively.
The output order does not matter, returning [9,0] is fine too.

Example 2:

Input:
s = "wordgoodstudentgoodword",
words = ["word","student"]
Output: []

I tried it in Python, but could not do it. Can you solve it?

 ... Can you provide a Python code to find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters?
assistant
#Here is Python code to find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.

class Solution:
     def findSubstring(self, s, words):
         """
         :type s: str
         :type words: List[str]
         :rtype: List[int]
         """
         lword = len(words[0])
         n = len(words)
         lwords = n * lword
         if not s or not lwords:
             return
         
         res = []
         dic = {} 
         for key in words:
             dic[key] = [0, 0]
         for key in words:
             dic[key][1] += 1
         for k in range(lword):
             i = k
             while i <= len(s)-lwords:
                 if not s[i:i+lword] in list(dic.keys()):
                     i += lword
                     continue
                 j = 0
                 start = i
                 while s[i:i+lword] in list(dic.keys()) and i<len(s):
                     key = s[i:i+lword]
                     dic[key][0] += 1
                     while dic[key][0] > dic[key][1]:
                         dic[s[start:start+lword]][0] -= 1
                         j -= 1
                         start += lword
                     j += 1
                     i += lword
                     if j==n:
                         res.append(start)
                         dic[s[start:start+lword]][0] -= 1
                         j -= 1
                         start += lword
                 for key in list(dic.keys()):
                     dic[key][0] = 0
         return res