Problem
Ask
Submissions

Problem: Substring with Concatenation of All Words

Medium
30 min
Explore how to solve the problem of finding substrings in a string that are concatenations of all given words exactly once using the sliding window technique. Understand constraints, validate your grasp with examples, and implement an efficient solution to handle permutations and string indexing.

Statement

You are given a string, s, and an array of strings, words. All strings in words are of the same length.

A concatenated string is a string that contains all the words in words exactly once, in any order, concatenated together without any intervening characters.

Formally, a concatenated string is a permutation of all words joined together. For example, if words = ["ab", "cd", "ef"], then the following are all valid concatenated strings: "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", "efcdab". However, "acdbef" is not valid because it is not formed by concatenating all the words in any order.

Your task is to return all starting indices of substrings in s that are concatenated strings.

You may return the indices in any order.

Constraints:

  • 11 \leq s.length 103\leq 10^3

  • 11 \leq words.length 1000\leq 1000

  • 11 \leq words[i].length 30\leq 30

  • s and words[i] consist of lowercase English letters.

Problem
Ask
Submissions

Problem: Substring with Concatenation of All Words

Medium
30 min
Explore how to solve the problem of finding substrings in a string that are concatenations of all given words exactly once using the sliding window technique. Understand constraints, validate your grasp with examples, and implement an efficient solution to handle permutations and string indexing.

Statement

You are given a string, s, and an array of strings, words. All strings in words are of the same length.

A concatenated string is a string that contains all the words in words exactly once, in any order, concatenated together without any intervening characters.

Formally, a concatenated string is a permutation of all words joined together. For example, if words = ["ab", "cd", "ef"], then the following are all valid concatenated strings: "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", "efcdab". However, "acdbef" is not valid because it is not formed by concatenating all the words in any order.

Your task is to return all starting indices of substrings in s that are concatenated strings.

You may return the indices in any order.

Constraints:

  • 11 \leq s.length 103\leq 10^3

  • 11 \leq words.length 1000\leq 1000

  • 11 \leq words[i].length 30\leq 30

  • s and words[i] consist of lowercase English letters.