Shortest Deletion for a Distinct Remainder
Problem statement
Given a case-sensitive printable-ASCII string, delete one contiguous substring so that every remaining character is distinct.
Return the minimum number of deleted characters. Deleting zero characters is allowed, and deleting the entire string is also a valid fallback.
Function
minDeletionForDistinct(text: String) → intExamples
Example 1
text = "abca"return = 1Deleting either occurrence of a leaves three distinct characters.
Example 2
text = "abc"return = 0The original string already contains no repeated character.
Constraints
0 <= text.length <= 10^5textcontains printable ASCII characters.