|
| 1 | +# 0030. [Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/?envType=study-plan-v2&envId=top-interview-150) |
| 2 | + |
| 3 | +You are given a string `s` and an array of strings `words`. All the strings of `words` are of **the same length**. |
| 4 | + |
| 5 | +A **concatenated string** is a string that exactly contains all the strings of any permutation of `words` concatenated. |
| 6 | + |
| 7 | +- For example, if words` = ["ab","cd","ef"]`, then `"abcdef"`, `"abefcd"`, `"cdabef"`, `"cdefab"`, `"efabcd"`, and `"efcdab"` are all concatenated strings. `"acdbef"` is not a concatenated string because it is not the concatenation of any permutation of `words`. |
| 8 | + |
| 9 | +Return an array of _the starting indices_ of all the concatenated substrings in `s`. You can return the answer in **any order**. |
| 10 | + |
| 11 | +#### **Example 1:** |
| 12 | + |
| 13 | +<pre><code><strong>Input:</strong> s = "barfoothefoobarman", words = ["foo","bar"] |
| 14 | +<strong>Output:</strong> [0,9] |
| 15 | +<strong>Explanation:</strong> |
| 16 | +The substring starting at 0 is "barfoo". It is the concatenation of ["bar","foo"] which is a permutation of words. |
| 17 | +The substring starting at 9 is "foobar". It is the concatenation of ["foo","bar"] which is a permutation of words. |
| 18 | +</code></pre> |
| 19 | + |
| 20 | +#### **Example 2:** |
| 21 | + |
| 22 | +<pre><code><strong>Input:</strong> s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"] |
| 23 | +<strong>Output:</strong> [] |
| 24 | +<strong>Explanation:</strong> |
| 25 | +There is no concatenated substring. |
| 26 | +</code></pre> |
| 27 | + |
| 28 | +#### **Example 3:** |
| 29 | + |
| 30 | +<pre><code><strong>Input:</strong> s = "barfoofoobarthefoobarman", words = ["bar","foo","the"] |
| 31 | +<strong>Output:</strong> [6,9,12] |
| 32 | +<strong>Explanation:</strong> |
| 33 | +The substring starting at 6 is "foobarthe". It is the concatenation of ["foo","bar","the"]. |
| 34 | +The substring starting at 9 is "barthefoo". It is the concatenation of ["bar","the","foo"]. |
| 35 | +The substring starting at 12 is "thefoobar". It is the concatenation of ["the","foo","bar"]. |
| 36 | +</code></pre> |
| 37 | + |
| 38 | +#### **Constraints:** |
| 39 | + |
| 40 | +- <code>1 <= s.length <= 10<sup>4</sup></code> |
| 41 | +- `1 <= words.length <= 5000` |
| 42 | +- `1 <= words[i].length <= 30` |
| 43 | +- `s` and `words[i]` consist of lowercase English letters. |
0 commit comments