DIY: Valid Palindrome II

Solve the interview question "Valid Palindrome II" in this lesson.

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 is an example input 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 validPalindrome(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.