Encode run-length

Write codeMedium15 min

Your task

A log shipper shortens noisy lines before upload. Given a string of lowercase letters, build its run-length form: each maximal run of a repeated character becomes the character followed by the run's length in decimal (lengths can be multi-digit, and 1 is written explicitly). Ship whichever is better: return the encoded form only if it is strictly shorter than the original; otherwise return the original. For example, 'aaabbbbbcc' becomes 'a3b5c2', but 'ab' stays 'ab' because 'a1b1' is longer.

Examples

compress_log(s: str) -> str
Example 1
Inputcompress_log("aaabbbbbcc")
Output"a3b5c2"