1193. Strange Printer

MediumDynamic ProgrammingInterval DP

A strange printer prints one contiguous run of the same character per operation and may overprint existing characters. Given a target string s, return the minimum number of print operations needed. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the minimum number of prints.

Examples

Example 1
Input: {"s":"aaabbb"}
Output: 2
Explanation: Print a's, then b's.
Example 2
Input: {"s":"aba"}
Output: 2
Explanation: Print 'aaa' then overprint 'b'.
Example 3
Input: {"s":"a"}
Output: 1
Explanation: One print.

Constraints

Asked by

BloombergMicrosoftAmazonGoogle
Solve this problem in the editor →