AmazonOA #236
Minimal Unique Segments
Estimated MediumJudge-ready
Cut a lowercase string into non-empty contiguous segments so that no character appears more than once within a segment; find the minimum number of segments. Characters cannot be reordered or skipped.
Input
One line containing the string. 1≤length≤100000, lowercase letters only.
Output
Output a single integer, the answer.
Example 1
Input:
abac
Output:
2
Example 2
Input:
aaaa
Output:
4
Example 3
Input:
abcabc
Output:
2
Example notes
The answers are 2, 4 and 2; abcabc can be split into abc and abc.
Editorial
Loading solution…