Problem of the day
If the given string is S = "abcba", then the possible substrings are "abc" and "cba". As "abc" starts with a lower index (i.e. 0, "cba" start with index 2), we will print "abc" as our shortest substring that contains all characters of 'S'.
The only line of input contains a string 'S' i.e. the given string.
The only line of output contains a string i.e. the shortest substring of 'S' which contains all the characters of 'S' at least once.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1 <= N <= 10^5
'S' only contains lowercase English-Alphabet letters.
Where 'S' is the given string and ‘N’ is the length of ‘S’.
Time Limit: 1 sec
aabcabb
abc
Some of the possible substrings are "aabcabb", "aabc", "abcab", "abc", etc. Out of all these substrings, we will have "abc", "bca" and "cab" with the shortest length. As "abc" appear earliest in the string, we will print "abc" in the output.
cddeyys
cddeyys