Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome With One Deletion

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

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

Navi uses short identifiers in parts of its application flows. Given a string s, determine whether it is possible to make s a palindrome by deleting at most one character.

Return True if s is already a palindrome or can become one after deleting exactly one character. Otherwise, return False.

Formal Specification

Implement valid_palindrome(s), where s is a string. The function must return a boolean. Characters are compared exactly as provided, including case and non-alphanumeric characters. A deletion removes one character and preserves the order of all remaining characters.

Constraints

  • 1 <= len(s) <= 10^5
  • s contains printable ASCII characters
  • At most one character may be deleted
  • Character comparisons are case-sensitive

Function Signature

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