pyassistant

Delete-to-Compress RLE Minimization

(Hard): Given a string s, you may delete at most k characters (from anywhere in the string). After deletions, the string is encoded using a standard run-length encoding (RLE) where each maximal run of the same character c with length L contributes 1 for the character itself plus the number of digits in L if L > 1 (i.e., 'a' -> length 1, 'a2' -> length 2, 'a10' -> length 3, 'a100' -> length 4). Your task is to compute the minimum possible length of the RLE of s after performing up to k deletions. Notes: - Deletions can be made in any positions and are not required to be contiguous. - The RLE contribution increases exactly when the run length reaches 1 (start of the run), 2, 10, 100, etc. - Return the minimal achievable encoded length as an integer. Constraints (for guidance): - 1 <= len(s) <= 150 - 0 <= k <= len(s)

Example:

Input:
('aaabbaaacc', 3)
Output:
3

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.