Check near-palindrome with one deletion
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This interview question evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer for Check near-palindrome with one deletion states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Constraints
- 0 <= len(s) <= 10^5
- s consists of lowercase (or arbitrary) characters
- An empty string and a single-character string are palindromes (return [True, -1])
- If s is already a palindrome, the deletion index is -1 (no deletion needed)
Examples
Input: ("aba",)
Expected Output: [True, -1]
Explanation: Already a palindrome, so no deletion is needed; index is -1.
Input: ("abca",)
Expected Output: [True, 1]
Explanation: First mismatch at b vs c; deleting index 1 ('b') leaves 'aca', a palindrome.
Hints
- Use two pointers from both ends. As long as characters match, move inward.
- At the first mismatch, only two repairs are possible: delete the left character or delete the right one. Check if either remaining substring is a palindrome.
- If you reach the middle with no mismatch, the string was already a palindrome — return -1 for the index. If both repair attempts fail, it's impossible.