Write a function that compresses a string using the Run-Length Encoding (RLE) algorithm.
HardProblem Statement
Write a function that compresses a string using the Run-Length Encoding (RLE) algorithm.
Sample Input
"aaabccccdd"
Sample Output
a3b1c4d2
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Compress a string using Run-Length Encoding
function runLengthEncode(str) {
// Initialize an encoded string and counter
// Iterate through characters, updating the counter for repeated characters
// Append the count and character when a different character is encountered
}
console.log(runLengthEncode("aaabccccdd"));
Input
"aaabccccdd"
Expected Output
a3b1c4d2