Ctrl K

Palindrome With One Eraser Stroke

Easy
You are given a string text of lowercase English letters. You may erase at most one character from it (erasing nothing is also fine). Return True if the string can then read the same forwards and backwards, and False otherwise.
Example 1
text="radlar" → True

Erase the l to get the palindrome radar.

Example 2
text="noon" → True

The string already reads the same both ways; nothing needs erasing.

Example 3
text="abcdba" → True

Whichever single letter you erase, the middle cd never matches.

Constraints
  • 1 ≤ len(text) ≤ 2 · 10⁵
  • text consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRise and Fall Lineup EasyCheapest Mirror String EasyPieces Without Shared Letters MediumA Note From Headline Cutouts MediumMirror Chunk Split Hard
loading Python…
Input
text="radlar"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.