Your question is Palindrome With One Removal. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Instagram uses lightweight text-processing checks in several caption and messaging workflows. Given a string, determine whether it is already a palindrome or can become one after removing at most one character.
A palindrome reads identically from left to right and right to left. Comparisons are case-sensitive, and every character, including spaces and punctuation, must be considered.
Implement valid_palindrome(s):
s, a string containing printable ASCII characters.True if s is a palindrome after removing zero or one character. Otherwise, return False.Your solution should use O(1) auxiliary space and avoid trying every possible deletion when a mismatch can identify the only relevant candidates.
def valid_palindrome(s):