The problem
A station name is written as a string s of lower-case letters. Return True if it reads the same forwards and backwards after you delete at most one character. Deleting nothing is allowed.
almost_palindrome("abca") # True: delete "b" (or "c")
almost_palindrome("racecar") # True: nothing to delete
almost_palindrome("abcda") # False: needs two deletions
Limits
- Up to 200,000 letters.
Builds on ARRS-2 Two pointers and ARRS-6 Strings as arrays.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
9 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | Delete one | Not run | |
| 2 | Already a palindrome | Not run | |
| 3 | Needs two deletions | Not run | |
| 4 | Only the right deletion works | Not run | |
| 5 | Only the left deletion works | Not run | |
| 6 | Short strings | Not run | |
| 7 | Delete at the very end | Not run | |
| 8 | 200,000 letters, True | Not run | |
| 9 | 200,000 letters, False | Not run |