Stack Bash - Master data structures and algorithms

Smallest subarray that covers set

Let's say you're given a string, and a set of characters that you're looking for in that string.
Find the shortest substring that contains all the characters in the set.
Your function should return the start and end indices of the substring in a tuple.
For example, given the following input:
search_string = "bitttcoin"
character_set = {"i", "c"}
The function's output should be (5, 7) since all characters in the set (i and c) appear in the shortest substring coi of the search string bitttcoin.
Note that the correct substring bitttcoin is shorter than the other: bitttcoin.
Note that the order that characters appear in the substring doesn't matter.
Keep in mind that characters could be repeated in the input string.

Try it


6 Essential Hash Tables Coding Interview Problems

Master Hash Tables by trying the coding challenges below.
  1. 1.Two sumEasy
  2. 2.Palindrome CheckEasy
  3. 3.Cover SetMedium
  4. 4.Missing numberMedium
  5. 5.Crypto ExchangeMedium
  6. 6.Distinct SubarrayHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.