Check if a String Is a Palindrome (and Variants)

Problem First, determine whether a string is a palindrome — it reads the same forwards and backwards. Then handle the variant: return true if the string can be made a palindrome by removing at most one character.

Input / Output

  • Input: string s.
  • Output: boolean for each variant.

Constraints

  • 1 ≤ |s| ≤ 10^5.
  • O(1) extra space is expected — building a reversed copy is the answer to beat.

Example

  • "aba" -> true
  • "abca" -> true (remove 'c')
  • "abc" -> false
added …
LeaderboardSalaryAccount