source: found as a demo task in interactive interview platform of T-Bank (2024), for "SRE-engineer" interview.
Given a sequence of capital latin letters, you are tasked to replace all substrings consisting of repetition of the same letter with that letter followed by a number of repetitions. Single letters should be copied as-is.
Input: string to be encoded
Answer: encoded version of the string
Example:
input:
ABAACCCAZZZZZA
answer:
ABA2C3AZ5A