Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function that compresses a string using the Run-Length Encoding (RLE) algorithm.

Hard

Problem 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"));
Log in or sign up to run or submit your code.Log inSign up
Input
"aaabccccdd"
Expected Output
a3b1c4d2