EASYasked at 2 companies

Count Prefix and Suffix Pairs I

A easy-tier problem at 78% community acceptance, tagged with Array, String, Trie. Reported in interviews at Autodesk and 1 others.

Founder's read

Count Prefix and Suffix Pairs I shows up in live assessments at companies like Autodesk and Capital One. The problem looks straightforward on the surface: you're counting pairs of words where one is both a prefix and suffix of another. Most candidates jump straight to nested loops and string slicing, which works but misses the actual pattern. The 77% acceptance rate is misleading. That number counts everyone who submits anything that passes the sample cases. In the real assessment, you'll have a few seconds to spot the trick before panic mode starts. StealthCoder reads the problem statement and surfaces the optimal approach instantly, invisible to the proctor, so you're never guessing under pressure.

Companies asking
2
Difficulty
EASY
Acceptance
78%

Companies that ask "Count Prefix and Suffix Pairs I"

If this hits your live OA

Count Prefix and Suffix Pairs I 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The trap is overthinking it. Yes, you can brute force: check every pair of words, test if word A is both a prefix and suffix of word B. That passes, but it's slow at scale. The real pattern uses a Trie or rolling hash to avoid redundant string comparisons. A Trie lets you build prefix structure once, then for each word, check if it could be a suffix of something else by reversing. Rolling hash (like Polynomial hash or Rabin-Karp) lets you compute prefix and suffix hashes in linear time without actually comparing substrings. Most engineers don't think about hashing for this type of problem. They see 'prefix' and 'suffix' and default to string matching. When you hit this live and the naive solution is too slow, StealthCoder gives you the hash-based or Trie-based pattern in seconds, so you can code confidently instead of rewriting under time pressure.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Count Prefix and Suffix Pairs I 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. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Prefix and Suffix Pairs I interview FAQ

Is this really an easy problem or does the acceptance rate lie?+

Acceptance rate counts submissions, not interview performance. The problem is easy conceptually (nested loops work) but the optimization isn't obvious. In a live OA, the easy win is the nested loop; the hard part is recognizing when and why you need Trie or rolling hash, which isn't something you drill often.

What's the trick I'm supposed to see?+

Prefix and suffix checks are expensive when done naively on every pair. Use a Trie to store all words by prefix structure, then for each word, reverse it and check if that reversed form exists in the Trie. Rolling hash is the other pattern: compute prefix and suffix hashes in one pass instead of comparing substrings.

How does this relate to the Trie and Hash Function topics?+

Trie is the textbook approach for prefix/suffix matching problems. Hash Function (rolling or polynomial hash) is the speedup: instead of comparing strings, compare their hashes. Both avoid the O(n^2 * m) substring-comparison trap. Autodesk and Capital One both ask prefix/suffix problems, so knowing both patterns is smart.

Will nested loops with string slicing fail on the OA?+

Depends on test case size. If words are short and count is small, nested loops pass. At larger scale, you'll timeout. The safe move is Trie or rolling hash from the start. You don't want to burn 5 minutes rewriting during the assessment.

How should I prepare for this specific problem?+

Code the brute-force solution first to ensure you understand the logic. Then implement Trie-based or rolling hash variant. In a live OA, if the simple approach feels right, code it. If you sense it's too slow, switch immediately. StealthCoder surfaces the optimized pattern if you blank, so you're never stuck choosing.

Want the actual problem statement? View "Count Prefix and Suffix Pairs I" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.