Strange Printer

There is a strange printer with the following two special properties:

  • The printer can only print a sequence of the same character each time.
  • At each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.

Given a string s, return the minimum number of turns the printer needed to print it.

Example 1
Inputs = "aaabbb"
Output2
Print "aaa" first and then print "bbb".
Example 2
Inputs = "aba"
Output2
Print "aaa" first and then print "b" from the second place of the string, which will cover the existing character 'a'.

Constraints

  • 1 <= s.length <= 100
  • s consists of lowercase English letters.

Asked at 9 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate