This question evaluates proficiency in string manipulation and encoding algorithms, specifically run-length encoding and decoding, along with attention to edge cases such as empty inputs and single-character runs and correct handling of repetition counts.
You are given a string consisting of lowercase English letters. You need to implement run-length encoding (RLE) and its corresponding decoding.
s
, e.g.,
"aaabccccd"
.
"a3b1c4d1"
.
"a3b1c4d1"
.
"aaabccccd"
.
Constraints:
0 <= len(s) <= 10^5
for both encoding and decoding inputs.
Tasks:
encode(String s)
and
decode(String encoded)
.