MEDIUMasked at 1 company

Longest Repeating Substring

A medium-tier problem at 63% community acceptance, tagged with String, Binary Search, Dynamic Programming. Reported in interviews at Coupang and 0 others.

Founder's read

Longest Repeating Substring is a medium-difficulty string problem that appears sporadically in assessments, most recently at Coupang. The acceptance rate sits at roughly 63 percent, but that number masks a sharp cliff: the naive approach fails instantly on large inputs, and the trick isn't always obvious under time pressure. You need to find the longest contiguous substring that appears at least twice in the given string, with no overlap allowed. If you hit this in your live assessment and the brute force immediately times out, StealthCoder surfaces a working solution in seconds while the proctor sees nothing.

Companies asking
1
Difficulty
MEDIUM
Acceptance
63%

Companies that ask "Longest Repeating Substring"

If this hits your live OA

Longest Repeating Substring 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 core issue is that checking every substring against every other substring is O(n³) or worse, which collapses on strings longer than a few hundred characters. The solution hinges on binary search over the answer combined with a hash-based duplicate detection. You binary search on substring length, then for each candidate length, you use rolling hash to scan the string once and detect if any substring of that length repeats. This reduces the problem to O(n log n) time. The pitfall is hash collision: a weak hash function gives false positives, making you report a length that doesn't actually repeat. Rolling hash with a large prime modulus is standard here. Suffix array is a theoretical alternative but overkill and harder to implement correctly under pressure. StealthCoder is the safety net when you realize mid-assessment that your initial approach won't finish in time.

Pattern tags

The honest play

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

Longest Repeating Substring recycles across companies for a reason. It's medium-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.

Longest Repeating Substring interview FAQ

How do I know if binary search or dynamic programming is the right approach here?+

Binary search on the answer length paired with rolling hash is faster and simpler to code correctly in an interview. DP solutions exist but require more careful state management and are harder to debug under pressure. Binary search lets you test a single length in linear time, which is the efficiency win you need.

Why is my rolling hash solution getting wrong answers?+

Hash collision is the main culprit. Use a large prime modulus (10^9 + 7 is standard) and a non-trivial base (31 or 37 work well). Even then, a single hash value can collide. Store the actual substrings of the candidate length in a set alongside their hashes to verify hits and avoid false positives.

Is this problem still asked, or is it outdated?+

It's not a top-frequency problem, but Coupang has reported asking it. It's also a good stress test for understanding rolling hash and binary search on answers. If you see it in your OA, treat it as a bonus opportunity to demonstrate solid string algorithm knowledge.

What's the difference between this and finding the longest repeating character?+

This problem requires a substring of any length (not just one character) to appear twice without overlapping. That constraint makes it significantly harder because you can't just count character frequencies. You need to track positions and lengths, which is why rolling hash and binary search become necessary.

Should I use a suffix array or suffix tree?+

Both can solve this in linear time, but they're complex to implement correctly in 45 minutes. Binary search plus rolling hash is more practical for a live interview. Suffix structures are impressive if you code them flawlessly, but the cost of a bug is higher and the payoff is marginal on time complexity.

Want the actual problem statement? View "Longest Repeating Substring" 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.