Expand a run-length encoded shift log

Python data engineering interview problem. Difficulty: beginner. Pattern: Strings. About 10 minutes. Free to practice.

The compact shift log from the compressor must be expanded back into the original sequence so humans can read it.

A shift log was compressed with run-length encoding, like a3b2c1. Before analysis it must be expanded back to the full text. Expand a string of letter-and-count pairs. Each letter is repeated the number of times written after it. An empty string stays empty. Write rle_expand(s). 'a3b2c1' becomes 'aaabbc'. An empty string gives ''. The starter file already has the function name and its print lines. Keep them and fill in the body.

Requirements

  • Read pairs of a letter and a number.
  • Repeat each letter that many times.
  • Join the pieces in order.
  • An empty string returns ''.

Constraints

  • The input is made of a letter followed by one or more digits, repeated.
  • Counts can have more than one digit, like a12.

Examples

Input: rle_expand('a3b2c1') Output: 'aaabbc' This input follows the stated rules and produces this output.

Topics: lakebench, python, strings.

More Python interview questions · All interview problems · Learn data engineering

beginner

Expand a run-length encoded shift log

Interview-style drill: Expand a run-length encoded string back into its original repeated sequence.

Expand a run-length encoded shift log back to the full string.