Strings String basics
124. Valid Palindrome II
You are given a string s of lowercase letters. You may delete at most one character from it. Return true
if s can then read the same from left to right as from right to left, and false otherwise.
"At most one" includes deleting nothing, so a string that already reads the same both ways gives true. The
character you delete can sit anywhere in s, the first and last positions included.
Example 1
Input: s = "racelcar"
trueExplanation: The first three letters mirror the last three, but the e and the l in the middle differ. Deleting the
l leaves "racecar", which reads the same both ways.
Example 2
Input: s = "refer"
trueExplanation: It already reads the same both ways, so nothing needs deleting.
Example 3
Input: s = "racecxars"
falseExplanation: Deleting the s at the end is not enough, because the x is still out of place. It takes two deletions to
reach "racecar".
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length ≤ 105sholds lowercase English letters only.
Clarifying questions
What you would ask an interviewer before writing any code.