Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome With One Mistake

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Palindrome With One Mistake. 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.

You need to log in / sign up to run or submit.

Problem

John Deere diagnostic systems may receive field equipment codes containing one extra or mistyped character. Given a string s, determine whether it is a palindrome after removing at most one character.

A palindrome reads identically from left to right and right to left. The comparison is case-sensitive, and characters must not be normalized or ignored.

Formal Specification

Implement valid_almost_palindrome(s), where s is a string. Return True if s is already a palindrome or can become one by deleting exactly one character. Return False otherwise.

Constraints

  • 1 <= len(s) <= 10^5
  • s contains printable ASCII characters
  • At most one character may be deleted
  • The algorithm should use O(n) time and O(1) extra space

Function Signature

def valid_almost_palindrome(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output