Maximum Number of Non-overlapping Palindrome Substrings

You are given a string s and a positive integer k.

Select a set of non-overlapping substrings from the string s that 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
Inputs = "abaccdbbd", k = 3
Output2
We can select "aba" and "dbbd", both of which are palindromes with length at least 3, and no selection can contain more than two valid substrings.
Example 2
Inputs = "adbcda", k = 2
Output0
There is no palindrome substring of length at least 2 in the string.

Constraints

  • 1 <= k <= s.length <= 2000
  • s consists of lowercase English letters.

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate