#K35277. Longest Subsequence with At Most Two Occurrences
Longest Subsequence with At Most Two Occurrences
Longest Subsequence with At Most Two Occurrences
Given a string s consisting of lowercase English letters, determine the length of the longest subsequence such that each character appears at most twice.
More formally, if every character (c) in the string appears (f(c)) times, then the answer is (\sum_{c}\min(f(c), 2)).
For example, if s = aabbcccc
, then the longest valid subsequence is aabbcc
which has length 6.
inputFormat
A single line input containing the string s, where (1 \leq |s| \leq 10^6) and s contains only lowercase English letters.
outputFormat
A single integer representing the length of the longest subsequence in which any character appears at most twice.## sample
aabbcccc
6