Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Compact a run-length encoded event log

Python data engineering interview problem. Difficulty: beginner. Pattern: Strings. About 10 minutes. Part of the Pro drill bank.

A verbose event log repeats the same character (or code) many times in a row. Compaction stores run-length pairs to save space.

Compact a run-length encoded event log (compress consecutive repeats).

Requirements

  • Consecutive equal characters become a count plus the character (format per tests).
  • Different characters start a new run.

Constraints

  • s: the raw log string.
  • Single characters are a run of 1 if the format includes the count.

Examples

Input: rle_compress('aaabbc') Output: 'a3b2c1' 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

Compact a run-length encoded event log

Interview-style drill: Compress a sequence of repeated status codes into a run-length encoded form.

Compact a run-length encoded event log (compress consecutive repeats).