Check Whether a String Can Become a Palindrome by Deleting at Most One Character
Company: Whatnot
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Overview: A string coding problem that asks whether a lowercase string can be turned into a palindrome by deleting at most one character, returning a boolean. It tests careful handling of mismatched characters, strings that are already palindromes, and an efficient solution for strings of up to 100,000 characters.
Constraints
- 1 <= len(s) <= 10^5
- s consists only of lowercase English letters 'a' to 'z'.
Examples
Input: ('a',)
Expected Output: True
Explanation: Minimum length 1: a single character is a palindrome, zero deletions.
Input: ('aa',)
Expected Output: True
Explanation: Length 2, equal letters: already a palindrome.
Hints
- Deleting zero characters is allowed, and a one-character string is already a palindrome, so start by asking when no deletion is needed at all.
- If the first and last characters are equal, ask whether either of them ever needs to be the deleted character, and what that says about the inner part of the string.
- Test your idea on abcbaa (the character to delete sits near the end) and on abc (no single deletion works).