Python interview question: run-length encoding

MediumArrays and strings

Problem

events is a courier app’s event stream, one lowercase letter per event. Replace each run of identical consecutive letters with the letter and the run length, leaving a run of one without a number. Return the compressed string.

def compress_events(events: str) -> str:

Example

Solve it free

Checked against hidden tests, right in your browser. No sign-up needed.

Skills it tests

More interview questions

All questions