text of lowercase English letters and an integer limit. The string is cut into pieces like this: take the longest prefix with at most limit distinct letters, cut it off, and repeat with what is left until the string is used up.
Before cutting you may replace one letter of the string with any other lowercase English letter, or leave the string as it is.
Return the largest number of pieces you can get.text="abab", limit=2 → 2
Change the third letter to c: "abcb". It is cut into "ab" and "cb", two pieces. Without the edit the whole string is one piece.
text="mmmm", limit=1 → 3
Change the second letter: "mzmm". The pieces are "m", "z", "mm", three in total.
text="pqrs", limit=4 → 1
len(text) ≤ 10⁴text consists of lowercase English letterslimit ≤ 26text="abab", limit=2
2
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.