Company: Microsoft SDE2_23june
Difficulty: medium
Determine the length of the shortest substring to delete from a string s of length n , so that the resulting string contains only distinct characters. A substring is a sequence of characters that appear consecutively within a string. If a substring is deleted, the remaining parts of the string are joined together. If no deletion is necessary, the answer should be 0. Example s = "abbcbcbk" The string uses only the characters a, b, c and k, so at most 4 distinct characters can remain. Therefore at least 8 - 4 = 4 characters must be deleted. For example, removing the bold substring in a bbcb cbk leaves acbk , which contains only distinct characters. No shorter deletion is possible, so the answer is 4. Function Description Complete the function findShortestSubstring in the editor with the following parameter: s : the string to analyze Returns: int : an integer representing the length of the shortest substring that should be deleted Constraints 1 ≤ n ≤ 10 5 s consists of lowercase Eng