96. String Compression

Acceptance — 0 accepted 0 submissions

Easy
StringsTwo Pointers
No companies listed
To save space, a sensor stores repeated readings in short form: 'aaabbc' becomes 'a3b2c1'.

Compress the string by writing each group of the same character followed by its count.

Input Format
A single string of lowercase letters.

Output Format
Print the compressed string.

Constraints
• 1 ≤ length ≤ 1000

Example 1

Input
aaabbc
Output
a3b2c1

Explanation Three a's, two b's and one c.

Example 2

Input
abc
Output
a1b1c1

Explanation No repeats, so each count is 1.

Example 3

Input
zzzzzzzzzzzz
Output
z12

Explanation Twelve z's become z12.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
a3b2c1
No results yet
Run your code to test it against the sample cases.
Problem List