Check If a Word Occurs As a Prefix of Any Word in a Sentence
A easy-tier problem at 69% community acceptance, tagged with Two Pointers, String, String Matching. Reported in interviews at Yelp and 1 others.
You're staring at a problem that sounds trivial: check if a word is a prefix of any word in a sentence. Easy difficulty, 68% acceptance rate, asked at Yelp and TCS. But the trap is real. Candidates overthink the string manipulation or botch the prefix logic under time pressure. This is the kind of problem where you need the pattern locked in before the OA timer starts, or you'll waste cycles on edge cases. If you blank on the exact comparison during your live assessment, StealthCoder surfaces a clean solution in seconds, invisible to the proctor.
Companies that ask "Check If a Word Occurs As a Prefix of Any Word in a Sentence"
Check If a Word Occurs As a Prefix of Any Word in a Sentence is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe trick is simple once you see it: split the sentence into words, then check if your target word matches the start of any word using string prefix methods. Most candidates either manually loop through character indices (slower, error-prone) or miss that built-in prefix checkers exist in their language. The real work is handling the comparison correctly. You need to check the exact length or use a method like startsWith or the slice-and-compare pattern. Two Pointers aren't the dominant pattern here despite the topic tag, but understanding how to walk through a sentence string and extract boundaries is core. String Matching is the actual mechanic: testing whether one string is a prefix of another. The acceptance rate hovers around 68%, which suggests most people get it right after a few submissions, but live OA nerves can flip that. StealthCoder is the hedge for the moment your brain locks up on the string comparison syntax.
Pattern tags
You know the problem.
Make sure you actually pass it.
Check If a Word Occurs As a Prefix of Any Word in a Sentence recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Check If a Word Occurs As a Prefix of Any Word in a Sentence interview FAQ
Is this problem as easy as the difficulty tag suggests?+
Yes and no. The logic is straightforward, but the gotcha is precision. You must compare the prefix correctly: checking equality up to the target word's length, or using a language's built-in prefix method. Most failures come from off-by-one errors or comparing the wrong substring bounds, not the algorithm itself.
What's the actual trick to solving this fast?+
Split the sentence into words first. Then iterate and test if your target word is a prefix of each word using startsWith, slicing, or direct character comparison. Pick one method and commit. Most languages have a prefix function; use it. Avoid manual index walking if you can.
Why is the acceptance rate only 68% if it's Easy?+
Nitty-gritty bugs. Edge cases like empty sentences, single-word sentences, or case sensitivity trip people up. The core logic is obvious, but the implementation details under time pressure cause resubmissions. Live OA conditions make it worse.
How does String Matching relate to prefix checking?+
Prefix checking is a specific String Matching problem: you're matching the start of one string against another, not the whole string. Understanding this distinction helps you avoid unnecessary comparisons and pick the right method for your language.
Do Yelp and TCS ask this the same way?+
Both companies reportedly ask it, but minor variations exist. Some OAs add constraints like case sensitivity or punctuation handling. The core pattern is identical. Practice the basic version and you'll adapt quickly if they tweak the requirements.
Want the actual problem statement? View "Check If a Word Occurs As a Prefix of Any Word in a Sentence" on LeetCode →