IBMOA #57
Minimum Number of Non-Empty Disjoint Segments
Estimated MediumJudge-ready
Split the string into non-empty, disjoint contiguous segments so that each character belongs to exactly one segment and no character repeats within a segment. Find the minimum number of segments.
Input
One line containing a lowercase string of length 1..200000.
Output
Output one integer, the answer.
Example 1
Input:
bcoc
Output:
2
Example 2
Input:
abdaa
Output:
3
Example 3
Input:
abcdefghijklmnopqrstuvwxyz
Output:
1
Example notes
The examples give 2, 3 and 1 respectively.
Editorial
Loading solution…