Run Length Encoding

Company: Rahi Platform Technologies_3nov

Difficulty: medium

Problem Statement

Run Length Encoding You are given a block of text. Encode every line of it with the simple run-length scheme described below. Read one line at a time and walk along it from left to right. At each moment you are looking at a run : the maximal group of equal characters that starts at the current position. A run of 2 to 9 equal characters is written as two characters: the length of the run, as one of the digits 2 … 9 , followed by the repeated character itself. So CCCC becomes 4C . A run longer than 9 is written as 9 followed by the character, which consumes nine of them; whatever is left of the run is then encoded by these same rules, starting again from rule 1. So eleven A characters become 9A2A . Characters that do not repeat are written as a literal segment: a 1 , then the characters themselves, then a closing 1 . A literal segment runs on for as long as the next character differs from the current one, and it stops right before the position where a new run of two or more equal charact