← 返回 salesforce 的题目列表Delete One Character Type to Minimize Unique-Character Segments
类型:online_judge
Given a string s containing only lowercase English letters.
You must choose one letter and remove all occurrences of that letter from s. Then partition the remaining string from left to right into non-empty contiguous segments.
A segment is valid if every character appears at most once within that segment.
Return the minimum number of valid segments obtainable after deleting one letter type.
If the remaining string is empty, return 0.
Input Format
One line containing the string s.
Output Format
Print one integer: the minimum possible number of segments.
Constraints
1 <= len(s) <= 100000
s contains only characters from 'a' to 'z'.
Examples
Example 1
Input:
avcccde
Output:
1
Removing 'c' produces "avde", which has no repeated characters and therefore needs only one segment.
Example 2
Input:
aabbcc
Output:
3
For example, removing 'a' produces "bbcc". An optimal partition is "b" | "bc" | "c", for a total of 3 segments.
Example
Input
avcccde
Output
1