Problem · String

Rightmost Longest Character Run

Learn this problem
EasyCapital OneINTERNOA

Problem statement

Given a string source consisting of lowercase English letters, find its longest contiguous substring made of one repeated character.

If several runs have the same maximum length, choose the rightmost one. Return a string formed by concatenating the selected character with the decimal length of its run.

Function

rightmostLongestCharacterRun(source: String) → String

Examples

Example 1

source = "bbaccdbbab"return = "c3"

The longest run is ccc, so the result is c3.

Example 2

source = "bbaacaa"return = "a2"

Three runs have length 2. The rightmost is the final aa, so the result is a2.

Constraints

  • 1 <= source.length <= 100
  • source contains only lowercase English letters.

More Capital One problems

drafts saved locally
public String rightmostLongestCharacterRun(String source) {
    // write your code here
}
source"bbaccdbbab"
expected"c3"
checking account