Valid Palindrome II
EasyTwo Pointerstwo pointers
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given a string s of lowercase letters, return true if s reads the same forwards and backwards after removing **at most one** character, and false otherwise.
Removing nothing is allowed, so a string that is already a palindrome qualifies. The solution should run in O(n) time.
Examples
Input: s = "aba"
Output: true
The string is already a palindrome.
Input: s = "abca"
Output: true
Remove the c (or the b) to get "aba" (or "aca").
Input: s = "abc"
Output: false
No single removal produces a palindrome.
Constraints
- 1 <= s.length <= 10^5
- s consists of lowercase English letters
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.