Follow

Today's Freebie. It's marked as easy.

This problem was asked by Amazon.

Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".

Implement run-length encoding and decoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. You can assume the string to be decoded is valid.

SPOILER ONE-LINER SOLUTIONS IN PYTHON 

Another Python Using Generators 

@Surasanji as soon as you send the check I will have a version with your name on it.. This one looks really easy though, the trick is making it pythonic. I can almost imagine a regex solution.

Basic non regex solution 

Basic non regex solution 

Basic non regex solution 

Basic non regex solution 

Basic non regex solution 

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves. A STEM-oriented instance.

No hate, No censorship. Be kind, be respectful

We federate with all servers: we don't block any servers.