Find the Rightmost Longest Character Run
Problem statement
You are given a string source containing lowercase English letters. Find the longest contiguous run of one letter.
If several runs have the same maximum length, choose the rightmost run. Return its letter followed by its length in decimal, with no space between them. For example, a run of twelve copies of x is written as x12.
Function
longestRun(source: String) → StringExamples
Example 1
source = "bbacccdbbab"return = "c3"The runs, from left to right, are bb, a, ccc, d, bb, a and b. The unique longest run is ccc, so return c3.
Example 2
source = "bbaacaa"return = "a2"The runs are bb, aa, c and aa. Three runs have length two. The final aa is the rightmost, so return a2.
Constraints
1 <= source.length <= 100sourcecontains only lowercase English letters.