Prepping for the 2027 recruiting cycle? Use code 2027RC for 10% off, valid until July 31st! Oh, and check out our members-only recruitment services.

Logo

Run-Length Encoding and Decoding

What this preview is

Run-Length Encoding and Decoding is a medium quant coding problem on language knowledge in Python.

Difficulty
Medium
Topic
Language Knowledge
Discipline
Quant development
Language
Python

Implementing run-length encoding and decoding in Python

This is a medium-difficulty coding problem that tests your ability to implement a practical lossless compression algorithm. You will build two complementary functions: one to compress data by replacing runs of identical characters with the character and its count, and another to decompress the result back to the original form.

The core challenge is handling the encoding rules precisely: single characters appear bare, while runs of length two or more include a count suffix. You must also decode a compressed string by parsing characters and their associated counts, then expanding them back. Strong solutions iterate cleanly through the input, track consecutive runs, and handle the parsing logic without off-by-one errors. Edge cases — such as single-character inputs, alternating characters with no runs, and multi-digit counts — require careful attention.

  • Grouping and counting consecutive identical elements
  • String parsing and number extraction
  • Preserving sequence order through compression and decompression
  • Handling boundary conditions between runs

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.