• Customer Support: admin@thealgorists.com
  • Feedback: We are listening to your every feedback, and taking action to constantly improve your learning experience. If you have any feedback, please use this form: https://thealgorists.com/Feedback.
  • If you are a student, email to admin@thealgorists.com to get special student discount.



Problem Statement:


You are given a string s and an array of strings words of the same length. Return all starting indices of substring(s) in s that is a concatenation of each word in words exactly once, in any order, and without any intervening characters.
You can return the answer in any order.

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

Example 2:
Input: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
Output: []

Example 3:
Input: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
Output: [6,9,12]

Solution:


This chapter is more of an exercise for you. My expectation would be that you have gone through all the previous Sliding Window problems ( Fundamentals and Minimum Window Substring, Grumpy Bartender, Longest Substring With Atmost Two Distinct Characters, Longest Substring With Atmost K Distinct Characters, Longest Substring Without Repeating Characters, Find All Anagrams ) and have spent quite a bit of time understanding the underlying concepts really well, and so I am leaving this problem for you to try and solve. I am pretty confident that you'd nail it. Anyways, if you get stuck, feel free to take help from code below. Solution for this problem is quite similar to that of Find All Anagrams problem.



Java Solution:



This is a Premium content. Please subscribe to access the code.
After subscribing please come back and refresh this page.




Python Solution:



This is a Premium content. Please subscribe to access the code.
After subscribing please come back and refresh this page.




The above content is written by:

Abhishek Dey

Abhishek Dey

A Visionary Software Engineer With A Mission To Empower Every Person & Every Organization On The Planet To Achieve More

Microsoft | University of Florida

View LinkedIn profile


If you have any feedback, please use this form: https://thealgorists.com/Feedback.




Subscribe to Our Youtube Channel

Follow Us On LinkedIn
wave