Rightmost Longest Character Run
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) → StringExamples
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 <= 100000textcontains lowercase English letters.