Substring with Concatenation of All Words
Given a string s and an array words of strings that all have the same length, return the starting indices of every substring of s that is a concatenation of every word in words exactly once, in any order, with no characters in between.
Open official problem prompt ↗Find every position where s contains a back-to-back arrangement of all the given words, each used exactly once.
Reading a sentence chopped into fixed-width blocks and finding where a specific bag of blocks appears in a row, in any order but with no gaps.
- Input
- s = "barfoothefoobarman", words = ["foo","bar"]
- Output
- [0, 9]
- Why
- "barfoo" starts at index 0 and "foobar" starts at index 9; each is a permutation of the two words.
1 <= s.length <= 10^41 <= words.length <= 50001 <= words[i].length <= 30All words[i] have the same lengths and words[i] consist of lowercase English letters