Check for a Palindrome after at Most One Deletion

Quick Overview

Check for a Palindrome after at Most One Deletion. Return whether deleting zero or one character from s can leave a palindrome.

Check for a Palindrome after at Most One Deletion

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return whether deleting zero or one character from s can leave a palindrome. The remaining characters keep their original order. ```cpp class Solution { public: bool validPalindrome(string s); }; ``` ### Examples **Example 1:** ```text s = "raceacar" Output: true Explanation: Delete the middle a to obtain racecar. ``` **Example 2:** ```text s = "abcd" Output: false Explanation: No one-character deletion leaves matching outer and inner pairs. ``` ### Constraints - The string contains 1..100000 English lowercase characters. ### Clarifying Questions Enforce the one-deletion limit and test both sides of the first unequal pair. ```hint Read the boundary condition At the first mismatched endpoints, which character could the only deletion remove? ``` ### Contract considerations Enforce the one-deletion limit and test both sides of the first unequal pair.

Overview: Check for a Palindrome after at Most One Deletion. Return whether deleting zero or one character from s can leave a palindrome.

Amazon logo
Amazon
Sep 10, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return whether deleting zero or one character from s can leave a palindrome. The remaining characters keep their original order.

class Solution {
public:
    bool validPalindrome(string s);
};

Examples

Example 1:

s = "raceacar"
Output: true
Explanation: Delete the middle a to obtain racecar.

Example 2:

s = "abcd"
Output: false
Explanation: No one-character deletion leaves matching outer and inner pairs.

Constraints

  • The string contains 1..100000 English lowercase characters.

Clarifying Questions Guidance

Enforce the one-deletion limit and test both sides of the first unequal pair.

Contract considerations

Enforce the one-deletion limit and test both sides of the first unequal pair.