Smallest subarray that covers set
MediumLet'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
Solution
6 Essential Hash Tables Coding Interview Problems
Master Hash Tables by trying the coding challenges below.
- 1.Two sumEasy
- 2.Palindrome CheckEasy
- 3.Cover SetMedium
- 4.Missing numberMedium
- 5.Crypto ExchangeMedium
- 6.Distinct SubarrayHard