FastPrepRightmost Longest Character Run

Rightmost Longest Character Run

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

You are given a nonempty string text. A run is a maximal contiguous group of one repeated character.

Find a run with maximum length. If several runs share that length, choose the rightmost one. Return the selected character followed immediately by the decimal run length.

Function

rightmostLongestRun(text: String) → String

Examples

Example 1

text = "bbacccd"return = "c3"

The run ccc is longer than every other run.

Example 2

text = "aabb"return = "b2"

Both runs have length two, so the rightmost run bb wins.

Constraints

  • 1 <= text.length <= 100000
  • text contains lowercase English letters.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String rightmostLongestRun(String text) {
    // Write your code here.
}
text"bbacccd"
expected"c3"
Checking account…