Shortest Substring with All Characters
Determine the shortest substring of the string S
that includes every character from S
at least once. If multiple shortest substrings exist, return the one that starts the earliest in S
.
Input:
The input contains a single string 'S'
consisting of only lowercase English letters.
Output:
Output the shortest substring of 'S'
that contains all unique characters from 'S'
.
Example:
Input:
"abcba"
Output:
"abc"
Explanation:
In the string S = "abcba"
, the substrings "abc"
and "cba"
both contain all characters of S
. "abc"
begins at index 0, earlier than "cba"
which begins at index 2. Hence, the answer is "abc"
.
Constraints:
1 <= N <= 10^5
S
consists only of lowercase English letters.
Where S
denotes the input string and N
is its length.
Note: You do not need to print anything; implement the function as per the requirements.

Find the shortest substring in a string that contains all unique characters.
Use a sliding window approach to find the shortest substring with all unique characters.
Keep track of the characters in the ...read more
Codalien Technologies Software Engineer interview questions & answers
Popular interview questions of Software Engineer


Reviews
Interviews
Salaries
Users

