Class Solution
-
- All Implemented Interfaces:
public final class Solution2472 - Maximum Number of Non-overlapping Palindrome Substrings\.
Hard
You are given a string
sand a positive integerk.Select a set of non-overlapping substrings from the string
sthat satisfy the following conditions:The length of each substring is at least
k.Each substring is a palindrome.
Return the maximum number of substrings in an optimal selection.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: s = "abaccdbbd", k = 3
Output: 2
Explanation: We can select the substrings underlined in s = "<ins> aba </ins>cc<ins> dbbd </ins>". Both "aba" and "dbbd" are palindromes and have a length of at least k = 3. It can be shown that we cannot find a selection with more than two valid substrings.
Example 2:
Input: s = "adbcda", k = 2
Output: 0
Explanation: There is no palindrome substring of length at least 2 in the string.
Constraints:
1 <= k <= s.length <= 2000sconsists of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegermaxPalindromes(String s, Integer k)-
-
Method Detail
-
maxPalindromes
final Integer maxPalindromes(String s, Integer k)
-
-
-
-