String Compression - aloalgo

String Compression

Medium

Write a function that performs a basic string compression using the counts of repeated characters.

For example, the string aaabbc would become a3b2c1.

You can assume the string has only lowercase letters (a-z).

Example 1

Input
"aaabbc"
Output
"a3b2c1"
Explanation:

'a' is repeated 3 times, 'b' is repeated 2 times, and 'c' is repeated 1 time.

Example 2

Input
"aabbcc"
Output
"a2b2c2"
Explanation:

Each character is repeated 2 times.

Example 3

Input
"abc"
Output
"a1b1c1"
Explanation:

Each character appears once.

Loading...
Input
"aaabbc"
Output
"a3b2c1"

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!