Smallest substring of all characters

Given an array with unique characters ‘arr’ and a string ‘str’, find the smallest substring of ‘str’ containing all characters of ‘arr’.

example:

getShortestUniqueSubstring(['x', 'y', 'z'], 'xyyzyzyx');
// zyx
getShortestUniqueSubstring(['x', 'y', 'z'], 'xyyzyzy');
// xyyz


Share Comments