Here at NML, one of our senior developers (and chief instigators of office humour), Charl, likes to keep the team on its toes with a regular coding challenge. They’ve become so popular – with prizes and instant office-cred involved – we’ve dubbed it the NML Charllenge.
In the spirit of open-source inspiration, here’s the latest one. If you’d like to tackle it, email your solution to us at email@example.com with the subject line: Coding Challenge.
Write a Run-Length encoding algorithm to encode a piece of text and be able to decode the result back to the original.
You can use any language of your choice, and send as many versions as you want. Your submission will be evaluated on the following:
Correct output for encoding and decoding (non-negotiable)
To recap, a run-length encoder takes a stream and encodes it by counting repeating bytes/characters and then outputting it as the number of the byte/characters that was repeated, plus the byte/character. So “aabbcde” will be “2a2b1c1d1e”.
Below is the runtime encode string you should be able to decode. A special prize for the first person to send in the decode text and tell us the name of the author. (We’ll know if you cheated by trying to figure out the latter before the former.)
(Note that the results of the any encode should be able to serve as the input for the next decode and that again for the next encode, without any loss of fidelity.)