MicrosoftOA #14
Compressed Representation Size
Estimated HardJudge-ready
Topics (AI-labelled)StringsPrefix & RangesTwo Pointers
Delete exactly K consecutive characters, then encode each run of repeated characters as its count followed by the character; a run of length 1 is written as just the character. Find the shortest possible encoding length. The original site's second example was miscalculated, so this site recomputed it independently.
Input
This site's input: the first line contains 1..100000 uppercase letters, and the second line contains K (0..N).
Output
Output a single integer, the answer.
Example 1
Input:
ABBBCCDDCCC
3
Output:
5
Example 2
Input:
ABCDDDCEFG
2
Output:
7
Example 3
Input:
AAAA
4
Output:
0
Example notes
Example 1: deleting DDC gives ABBBCCCC, encoded as A3B4C with length 5.
Example 2: the shortest length is 7; for example, deleting BC gives ADDDCEFG, encoded as A3DCEFG. The original site's 6 left out characters.
Example 3: deleting all characters leaves an empty encoding of length 0.
Editorial
Loading solution…