PinterestOA #1
Longest Contiguous Substring of Single Character (Rightmost)
Estimated EasyJudge-ready
Topics (AI-labelled)StringsTwo Pointers
You are given a string containing only lowercase English letters. Find the longest substring of contiguous identical characters; if several are tied in length, choose the rightmost one. Output the string formed by concatenating that character with the length of the substring.
Input
One line containing the string source, 1≤|source|≤100, consisting only of a-z (source constraint).
Output
Output one character followed by the length of the longest contiguous run; on a tie, take the rightmost run.
Example 1
Input:
bbaacaa
Output:
a2
Example 2
Input:
bbbeed
Output:
b3
Example 3
Input:
ccc
Output:
c3
Editorial
Loading solution…