Stack Bash - Master data structures and algorithms

Compress string

Medium
Compression is a way to represent data in a way that requires less space.
Let's say you're given a string of only letters:
bbbddrrrr
Write a function that returns the string in its compressed form:
b3d2r4
The output contains each letter in the input followed by the number of times it appears.

Try it

Solution

6 Essential Strings Coding Interview Problems

Master Strings by trying the coding challenges below.
  1. 1.Reverse StringEasy
  2. 2.AnagramEasy
  3. 3.Reverse wordsMedium
  4. 4.String matchMedium
  5. 5.CompressionMedium
  6. 6.One edit awayHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.