The Maximum Number of Non-overlapping Palindrome Substrings coding problem gives you a string s and an integer k. You want to find the maximum number of non-overlapping palindrome substrings of length at least k. Each selected substring must be a palindrome, have length ≥ k, and must not overlap with any other selected substring.
Microsoft, SoFi, Salesforce, LinkedIn, Oracle, and Walmart Labs include this problem because it combines palindrome detection (using DP or Manacher's algorithm) with a greedy interval selection. The greedy insight — always pick the shortest valid palindrome ending as early as possible — is the same as the classic interval scheduling maximization. This problem tests both string algorithms and greedy thinking.
DP palindrome check + Greedy selection: First, precompute isPalin[i][j] = whether s[i..j] is a palindrome (O(n²) DP or Manacher's). Then, greedily iterate left to right: for each position i, find the leftmost j ≥ i+k-1 such that s[i..j] is a palindrome. If found, select this substring (count++), move to j+1, and continue. This greedy "start as early, end as early as possible" maximizes the number of non-overlapping palindromes.
s = "aabbaabaab", k = 3.
For the Two Pointers String Greedy Dynamic Programming interview pattern, the "palindrome DP table + greedy interval selection" combination is reusable. Build the palindrome table once, then apply any interval selection strategy (earliest-end greedy for max count, or DP for weighted selection). Manacher's algorithm is the O(n) alternative to the O(n²) palindrome DP — worth knowing for follow-up questions.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Lexicographically Smallest Valid Sequence | Medium | Solve | |
| Palindromic Substrings | Medium | Solve | |
| Remove Adjacent Almost-Equal Characters | Medium | Solve | |
| Append Characters to String to Make Subsequence | Medium | Solve | |
| Minimum Number of Food Buckets to Feed the Hamsters | Medium | Solve |