Reported April 2020
Bloombergtwo pointers

Valid Palindrome

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The edge case that kills a naive Valid Palindrome solution is the string that filters down to nothing, or one stuffed with punctuation and digits. Bloomberg reported this one in April 2020, and it's a clean two-pointer problem dressed up as string cleanup. If your OA invite is sitting there, expect the same shape: lowercase, strip non-alphanumerics, compare mirrored characters. Most people get the idea in thirty seconds and then lose points on details. StealthCoder is the safety net if you blank mid-assessment, but the pattern here is simple enough that you should walk in with it already loaded.

The problem

Return whether s is a palindrome after converting letters to lowercase and removing every character that is not a letter or digit.
The empty filtered string is a palindrome.

Function
isValidPalindrome(s: String) → boolean

Examples
Example 1
s = "A man, a plan, a canal: Panama"
return = true
The filtered lowercase text is amanaplanacanalpanama.
Example 2
s = "race a car"
return = false
The filtered text differs at a mirrored pair.

Constraints
0 <= s.length <= 10^5.
s contains ASCII characters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to skip the filtered copy and run two pointers on the original string. Start one at index 0 and one at the end. Move the left pointer forward until it hits a letter or digit, move the right one backward the same way, then compare them lowercased. If they differ, return false. If the pointers cross, return true. That's O(n) time and O(1) space. The pitfalls are concrete. Don't let pointers run past each other while skipping junk, so keep the left < right check inside the inner loops. An empty string or all-punctuation string must return true. Use a real alphanumeric check, not just a letter check, because digits count. In a live OA, StealthCoder is the hedge if you freeze on the pointer loop bounds, but write it once by hand tonight and you won't need it.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Valid Palindrome cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as valid palindrome. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Valid Palindrome FAQ

How hard is Valid Palindrome really?+

It's easy. The logic is two pointers moving inward and comparing characters. The difficulty is in the details: skipping non-alphanumeric characters safely, handling case, and returning true for an empty filtered string. Bloomberg reported it in April 2020, so expect a clean version of this.

What's the trick to this problem?+

Use two pointers on the original string instead of building a cleaned copy. Advance each pointer past characters that aren't letters or digits, compare lowercased values, and stop when they cross. You get O(n) time and O(1) extra space with no allocation.

What edge cases should I test before submitting?+

Test an empty string, a string of only punctuation like ".,", a single character, and a mix of digits and letters like "0P". That last one should return false. Also test strings with leading and trailing junk so your skip loops don't go out of bounds.

Is it okay to build a filtered string first?+

Yes, it's correct. Filter to lowercase alphanumerics, then compare to its reverse. It uses O(n) extra space, which is fine for 10^5 characters. The two-pointer version is cleaner to explain and saves memory, so it's the one interviewers like more.

How do I prepare for this in 48 hours?+

Write the two-pointer solution from scratch twice without looking. Then run it on the two examples and your edge cases. Learn the alphanumeric check in your language and how to lowercase a single character. That's the whole problem, and it takes under an hour.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it