Reads the Same Both Ways
A phrase reads the same both ways when its letters and digits, read from the end back to the start, spell the same thing as read from the start. Upper and lower case count as the same, and every other character (spaces, punctuation) is ignored.
Given a string phrase, return true if it reads the same both ways, and false if not. A phrase with no letters or digits at all does.
Examples
phrase = "Never odd or even" → true
phrase = "Step on no pets!" → true
phrase = "Top spot, 2 go" → false
phrase = "12:21" → trueThe first phrase, with the spaces dropped and lower-cased, is "neveroddoreven", which is the same reversed. In the third, the 2 has nothing to match on the other side.
Constraints
- Between 0 and 50,000 characters. Letters are
a–zandA–Z, digits0–9; anything else is ignored. - Aim for O(n) time and O(1) extra memory: compare characters in place.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 10 on the judge, 6 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.