A sign-maker wants to know whether a slogan reads the same both ways, counting only letters and digits and ignoring case.
Write reads_same_both_ways(s: str) -> bool. Only a-z, A-Z and 0-9 count; a string with none of them reads the same both ways.
reads_same_both_ways("Step on no pets!") # True
reads_same_both_ways("Top spot, not a pot") # False
reads_same_both_ways("No 'x' in Nixon") # True
reads_same_both_ways("1a2") # False
reads_same_both_ways(" ,.;") # True
Up to 2 * 10^5 ASCII characters. Use O(1) extra space: no cleaned-up copy (the tests measure memory). ⭐ Bonus: a speed test earns a star in O(n).
Show hint
compare from both ends at once, letting each end skip characters that don't count.