Problem · String
Shortest Substring
Learn this problemProblem statement
Determine the length of the shortest contiguous substring that can be deleted from a string s so that the remaining string contains only distinct characters.
After deleting a substring, join the part before it with the part after it. If s already contains only distinct characters, return 0.
Function
findShortestSubstring(s: String) → intExamples
Example 1
s = "abcbbck"return = 3Deleting any one of three length-3 choices can leave abck, whose characters are all distinct. No shorter deletion works.
Example 2
s = "xabbcacpqr"return = 3Delete bca to obtain xabcpqr.
Constraints
1 <= s.length() <= 10^5scontains only lowercase English letters.