Valid Palindrome After Normalization
Updated
Problem statement
You are given a string s. Decide whether its letters and digits form a palindrome when letter case is ignored.
Look only at the characters that remain after these rules:
- Keep only ASCII letters
AthroughZ,athroughz, and digits0through9. Drop everything else. - Treat uppercase and lowercase versions of a letter as equal.
- Leave the kept characters in their original order. Do not rearrange them or delete any kept letter or digit.
Return true if the kept characters read the same forward and backward, and false otherwise. If no characters are kept, the empty sequence counts as a palindrome.
Function
isValidPalindrome(s: String) → booleanExamples
Example 1
s = "A!b?b,a"return = trueThe kept characters are A, b, b and a. Ignoring case gives abba. The first and last letters match, and so do the middle two. So the answer is true.
Example 2
s = "0P"return = falseBoth characters are kept: the digit 0 and the letter P. Ignoring case gives 0p. A digit never equals a letter, so the first and last characters differ. The answer is false.
Constraints
0 <= s.length <= 20000.- Each character is printable ASCII, with a code from
32through126, inclusive.
More Amazon Phone Screen questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Reverse a String ManuallyNewgen Software · PHONE SCREEN
- Reverse a String with Two PointersSnowflake · PHONE SCREENSnowflake interview questions
- Palindrome with One DeletionWhatNot · PHONE SCREENWhatNot interview questions
- Valid Word AbbreviationMeta · PHONE SCREENMeta interview questions
- Reverse a StringPersistent Systems · PHONE SCREEN
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Valid Palindrome IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions