Determine Whether a String Can Become a Palindrome After K Deletions
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Overview: Determine whether at most k deletions can turn a string into a palindrome while preserving character order. Develop a dynamic-programming or equivalent formulation that explores mismatched ends without enumerating every subsequence.
Read the full Meta Software Engineer interview experience this question came from
Constraints
- 0 <= len(s) <= 2000.
- 0 <= k <= len(s).
- s contains only lowercase English letters.
- Deleting fewer than k characters is allowed.
- Remaining characters preserve their original order.
- The solution does not enumerate subsequences.
Examples
Input: ('abcdeca', 2)
Expected Output: True
Explanation: This is the first source example; deleting b and e leaves acdca.
Input: ('acdcb', 1)
Expected Output: False
Explanation: This is the second source example; one deletion cannot produce a palindrome.
Hints
- Define the minimum deletions required for each two-ended substring.
- When endpoints differ, one of them must be deleted; when they match, keep both.