Check Whether a Gift Message Becomes a Palindrome After One Deletion

Last updated: November 29, 2026

Quick Overview

Given a gift message string of lowercase letters, return True if it is a palindrome or can become one by deleting at most one character.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a gift message string of lowercase letters, return True if it is a palindrome or can become one by deleting at most one character.

A light Amazon phone-screen question themed on a novelty gift-wrap feature. The interviewer checks two-pointer comparison from both ends and whether you branch only once at the first mismatch rather than trying every deletion.

What the Interviewer Expects
  • Compare characters from both ends with two pointers
  • On the first mismatch, try skipping the left or the right character
  • Avoid the O(n^2) approach of deleting each index
  • Keep the helper a plain range check
  • Test even and odd lengths
Key Topics to Cover
Two Pointers
Strings
Palindromes
Greedy
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if up to k deletions are allowed?
  • How would you ignore spaces, punctuation and case in a real message?
  • Return which index to delete, not just True or False.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: string s of lowercase letters, length up to 1e5. Output: True if s is a palindrome after removing zero or one character....

High-Level Design

Walk i from the start and j from the end while characters match. At the first mismatch the deleted character must be either s[i] or s[j], because every outer pair already matched. So check whe...


Submit Your Answer
Markdown supported