10038. Maximize the Number of Partitions After Operations
You are given a 0-indexed string
s
and an integerk
.You are to perform the following partitioning operations until
s
is empty:
- Choose the longest prefix of
s
containing at mostk
distinct characters.- Delete the prefix from
s
and increase the number of partitions by one. The remaining characters (if any) ins
maintain their initial order.Before the operations, you are allowed to change at most one index in
s
to another lowercase English letter.Return an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.
c++
1 |
|