Problem Statement: Substring with Concatenation of All Words Given a string s and a list of words words, you need 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. Each word in the list words has the same length. The length of the concatenated substring is the sum of the lengths of all the words, and the substring must consist of exactly one occurrence of each word from the list (in any order). Input: Output: Example: Example 1: Input: s = “barfoothefoobarman”, words = [“foo”, “bar”]Output: [0, 9]Explanation: The substring starting at index 0 is “barfoo”, and the substring starting at index 9 is “foobar”. Example 2: Input: s = “wordgoodgoodgoodbestword”, words = [“word”, “good”, “best”, “good”]Output: [8]Explanation: The substring starting at index 8 is “goodbestword”. Approach: Algorithm: Code Implementation: Python: from collections import Counterdef findSubstring(s, words): if not s or not words: return [] word_len = len(words[0]) word_count = len(words) word_map = Counter(words) # Frequency map of the words in ‘words’ result = [] # Sliding window of size word_len * word_count for i in range(word_len): left = i right = i current_count = 0 window_map = Counter() # Map to track the current window while right + word_len <= len(s): word = s[right:right + word_len] right += word_len if word in word_map: window_map[word] += 1 current_count += 1 # If the word count exceeds the expected count, move left pointer while window_map[word] > word_map[word]: left_word = s[left:left + word_len] window_map[left_word] -= 1 current_count -= 1 left += word_len # If we have found all words in the window, add to the result if current_count == word_count: result.append(left) else: # Reset the window if the word is not in the words list window_map.clear() current_count = 0 left = right return result Explanation: Time and Space Complexity: Example Walkthrough: Example 1: Input: s = “barfoothefoobarman”, words = [“foo”, “bar”] Example 2: Input: s = “wordgoodgoodgoodbestword”, words = [“word”, “good”, “best”, “good”]