K06
Log Run-Length Compression
Problem Statement & Objective
A server daemon produces raw log lines with consecutive repeating characters. To conserve disk bandwidth, compress consecutive identical characters into a single character followed by its repetition count (e.g., 'aaabb' becomes 'a3b2'). If a character occurs only once, output the character by itself without a count of 1.
Function Signature (Python)
compress_logs(s: str) -> strInput & Output Contract
Output Rule:Compressed string. Single occurrences omit the count digit '1'. Empty input returns empty string.
System Constraints
0 <= metin.length <= 10^5
metin consists of ASCII alphanumeric charactersExample Execution Walkthrough
metin = "aaabbc"
'a' repeats 3 times -> 'a3'
'b' repeats 2 times -> 'b2'
'c' repeats 1 time -> 'c'
result: "a3b2c"Example Test Scenarios (3)
Example 1
Input:
["aaabbccccd"]Expected Output:
"a3b2c4d1"Example 2: Çoklu Karakter Blokları
Input:
["wwwwaaadexxxxxx"]Expected Output:
"w4a3d1e1x6"Example 3: Tek Karakter
Input:
["k"]Expected Output:
"k1"