1246. String Compression II

HardDynamic ProgrammingString DP

Run-length encoding replaces each run of a repeated character by the character followed by its count (a count of 1 is omitted). Given a string s and an integer k, delete at most k characters to minimize the length of the run-length encoding of the remaining string. Return that minimum length. The input is JSON {s, k}.

Input: JSON {s, k}.

Output: Integer — the minimum encoded length.

Examples

Example 1
Input: {"s":"aaabcccd","k":2}
Output: 4
Explanation: Delete b and d to get 'a3c3'.
Example 2
Input: {"s":"aabbaa","k":2}
Output: 2
Explanation: Delete both b's to get 'a4'.
Example 3
Input: {"s":"aaaaaaaaaaa","k":0}
Output: 3
Explanation: 'a11' has length 3.

Constraints

Asked by

MicrosoftAmazonGoogle
Solve this problem in the editor →