#K44102. Longest Contiguous Subsequence Lengths
Longest Contiguous Subsequence Lengths
Longest Contiguous Subsequence Lengths
Given a string S consisting of lowercase English letters, your task is to determine, for each distinct character, the length of its longest contiguous subsequence in S. In other words, for each character, find the maximum number of times it appears consecutively in the string.
Mathematically, for each character \( c \) in S, you need to compute:
[ L(c) = \max{k \mid \text{there exists an index } i \text{ such that } S[i..i+k-1] = c^k }]
Input Example: For the input abcdddeee
, the output should be a:1 b:1 c:1 d:3 e:3
because:
- The longest contiguous sequence for 'a' is of length 1.
- The longest contiguous sequence for 'd' is of length 3.
- Similarly for others.
If the string is empty, output an empty line.
inputFormat
The input is provided via standard input. It consists of a single line containing a non-empty string S composed of lowercase English letters.
outputFormat
Output the longest contiguous subsequence lengths for each distinct character in the order that they first appear in S. For each character, print the result in the format character:count
. Separate each pair by a single space. If the input string is empty, print an empty line.
abcdddeee
a:1 b:1 c:1 d:3 e:3