shlogg · Early preview
Md Ariful Haque @mah-shamim

Strange Printer In Minimum Turns

Strange Printer problem: use dynamic programming to find min turns to print string s. Initialize dp[i][i] = 1, then fill table with same or different char logic. Result: dp[0][$n - 1]. Efficiently calculates min turns.

664. Strange Printer
Difficulty: Hard
Topics: String, Dynamic Programming
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:

Input: s = "aaabbb"
Output: 2
Explanation: Print "aaa" first and then print "bbb".

Example 2:

Input: s = "aba"
Output: 2
Explanation: Print "aaa"...