Meta VO Interview Question: Valid Palindrome II

13 Views
No Comments

Given a string s consisting of lowercase English characters, determine if you can make it a palindrome by removing at most one letter.

Example 1:

Input: s = "aba"
Output: true

Example 2:

Input: s = "abca"
Output: true

Example 3:

Input: s = "cupcua"
Output: true

Example 4:

Input: s = "abcde"
Output: false

This is a classic two-pointer palindrome variant. Scan from both ends toward the center, and when the characters differ, try deleting either the left or the right character once and check whether the remaining substring is a palindrome. Since only one deletion is allowed, the solution runs in O(n) time and O(1) extra space.

END
 0