As reported: Mastercard Code for Change online assessment (Aug 2026), question 1 — Minimum Turns to Type a String: Reena types in an insert mode where one turn writes a run of the same character from a start position to an end position, replacing what was there; given a lowercase string (length 1–100), find the minimum number of turns. The problem is LeetCode 664 — Strange Printer.
This is LeetCode 664 — Strange Printer. Our write-up: /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
Input: s = "aaabbb"
Output: 2
Explanation: Print "aaa" first and then print "bbb".
Example 2
Input: s = "aba"
Output: 2
Explanation: 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.
Code runner format: one JSON line: s. Implement strangePrinter(s).