DIY: Valid Palindrome II
Solve the interview question "Valid Palindrome II" in this lesson.
We'll cover the following
Problem statement
Write a function that takes a variable containing a string and checks whether you can make it a palindrome by deleting at most one character.
Input
The input will contain a string s
. The following two are example inputs to the function:
"dead"
Output
The output will be a Boolean representing whether the string can be converted to a palindrome or not. For the above two inputs, the outputs will be:
True
We can delete either e
or a
to make the string a palindrome.
Coding exercise
Implement the valid_palindrome(s)
function, where s
is the string. The function returns True
or False
depending on whether the string can be converted to a palindrome or not.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.