Reported June 2023
Motivetwo pointers

Valid Palindrome

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

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

The whole Motive Valid Palindrome question, reported in June 2023, hinges on one idea: you don't need a new data structure, just two indexes walking toward each other over the original string. If your OA invite lists this one, it's a warm-up with a few traps. You filter to letters and digits, lowercase everything, and the empty result counts as true. Candidates lose points on the edges, not the idea. StealthCoder sits invisibly on your desktop during the live assessment as a safety net, so if your mind goes blank on the pointer logic, you still have a working answer in front of you.

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 two pointers. Put one at index 0 and one at the last index. Move the left pointer forward until it hits a letter or digit, move the right pointer backward the same way, then compare the two characters in lowercase. A mismatch returns false. If the pointers cross, return true. This runs in O(n) time and O(1) extra space, which beats building a cleaned copy and reversing it, though that version is also acceptable. The common pitfalls are forgetting to guard the inner loops with left < right, which causes out-of-bounds reads on strings like ",.", and using a character check that misses digits. An empty string or all punctuation must return true. With s up to 10^5 characters, avoid repeated string concatenation inside a loop. If you blank during the real OA, StealthCoder can give you the loop structure so you only have to type and verify it.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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 Motive's OA.

Motive reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Valid Palindrome FAQ

How hard is the Motive Valid Palindrome question really?+

It's easy. The logic fits in about fifteen lines. The difficulty is in the details: skipping non-alphanumeric characters, handling case, and returning true for an empty filtered string. If you've written a two-pointer loop before, you can finish this quickly.

What's the trick to solving it?+

Use two pointers from both ends of the original string. Skip anything that isn't a letter or digit, compare lowercase versions, and stop when they meet. You avoid building a second string, so extra space stays constant.

What edge cases should I test before submitting?+

Test an empty string, a string of only punctuation like ",.", a single character, and digits mixed with letters such as "0P". The last one should return false. Also run both examples: the Panama sentence returns true and "race a car" returns false.

Can I just reverse the cleaned string and compare?+

Yes. Filter to lowercase alphanumerics, reverse it, and check equality. It's O(n) time but uses O(n) extra space. It's fine for 10^5 characters, but the two-pointer version is cleaner and shows you know the standard approach.

How do I prepare for this in 48 hours?+

Write the two-pointer version from scratch twice without looking. Practice the inner skip loops and the left < right guards. Then run the empty and punctuation-only cases by hand. Spend the remaining time on other short string problems that use the same pointer pattern.

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

OA at Motive?
Invisible during screen share
Get it