Code Room
CodingMediumcod-g1381
Subject StringsLevel Entry–Mid~15 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A log shipper shortens noisy lines before upload. Given a string of lowercase letters, build its run-length form: each maximal run of a repeated character becomes the character followed by the run's length in decimal (lengths can be multi-digit, and 1 is written explicitly). Ship whichever is better: return the encoded form only if it is strictly shorter than the original; otherwise return the original. For example, 'aaabbbbbcc' becomes 'a3b5c2', but 'ab' stays 'ab' because 'a1b1' is longer.

Implement
compress_log(s: str) → str
Examples
in["aaabbbbbcc"]out"a3b5c2"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.