Loading...
You are given a string s of lowercase English letters. Perform the following operation exactly once:
s. Choosing a letter that does not appear in s leaves the string unchanged.After the deletion, partition the remaining string into contiguous non-empty segments such that no letter appears more than once within any segment. Choose the deleted letter that minimizes the number of segments in an optimal partition. Return that minimum number of segments.
If the deletion leaves the string empty, the answer is 0.
Input: s = "abcccde"
Output: 1
Explanation: Deleting 'c' leaves "abde", which has no repeated letter, so a single segment suffices.
Input: s = "abdaa"
Output: 1
Explanation: Deleting 'a' leaves "bd", a single segment with no repeats.
Input: s = "aaaaa"
Output: 0
Explanation: Deleting 'a' leaves the empty string, which needs 0 segments.
s.length ≤2⋅105s consists only of lowercase English letters.Click "Run" to test with sample cases or "Submit" to run all tests.