Strange Printer

HardDynamic Programminginterval dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A strange printer works on a line of positions. In one turn it picks a contiguous range of positions and a single character, and prints that character over the whole range, replacing whatever was there. Every turn prints exactly one kind of character. Starting from a blank line, return the minimum number of turns needed to make the line read exactly s.

Examples

Input: s = "aaabbb"
Output: 2
Print "aaa" then "bbb".
Input: s = "aba"
Output: 2
Print "aaa", then print "b" over the middle position.

Constraints

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

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More interval dp problems