Find Repetition
Reported by candidates from Pure Storage's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Pure Storage reported this one in March 2025, and it looks fancier than it is. Strip the wording and it's a scan for the longest run of back-to-back matches of a tiny string inside a huge one. The short string is under 10 characters and the long one can hit a million, so the shape of the solution matters more than cleverness. If you blank on the run-counting logic during the live OA, StealthCoder sits invisibly on your screen as a safety net. But this is a ten-minute problem if you see the reduction.
The problem
You are given a short string short_s and a long string long_s. Return the largest integer k such that short_s repeated k times appears as one contiguous substring of long_s. The copies in a repetition must be adjacent and non-overlapping. Return 0 if either string is empty or if short_s does not occur. Function findRepetitions(short_s: String, long_s: String) → int Examples Example 1 short_s = "AB" long_s = "ABBAC" return = 1 AB occurs once in ABBAC, so the maximum consecutive repetition count is 1. Example 2 short_s = "AB" long_s = "ABCABCABAB" return = 2 AB starts at indices 0, 3, 6, and 8. Only the occurrences at indices 6 and 8 are adjacent, forming ABAB, so the answer is 2. Constraints 0 <= short_s.length < 10 0 <= long_s.length < 1000000
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: find every index where short_s matches in long_s, then look for the longest chain where each next match starts exactly len(short_s) later. Walk i from 0 to n-m. At each i, if long_s[i:i+m] equals short_s, count how many consecutive copies follow by jumping m at a time. Track the max. The common pitfall is the overlap case. With short_s like AA and long_s AAA, matches at 0 and 1 overlap, so they don't chain. Only jump by m, never by 1, inside a run. Another pitfall is forgetting the empty-string case, which must return 0 before you loop. Since m is under 10, direct comparison per index costs about 10n, which is fine for a million characters. Avoid building a repeated string and calling find in a loop, that gets slow. StealthCoder is your hedge if the index math slips under pressure during the live OA.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Find Repetition 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as maximum repeating substring. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Pure Storage's OA.
Pure Storage reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Repetition FAQ
How hard is Find Repetition really?+
Easy to easy-medium. The logic is a single pass with a nested jump loop. The difficulty is in edge cases like empty strings and overlapping matches, not in the algorithm. If you can write a substring comparison and a counter, you can solve it.
What's the trick to get the right answer?+
At each index, check whether short_s matches. If it does, keep jumping forward by len(short_s) while it keeps matching, counting copies. Record the max count. Jumping by the full length is what enforces the non-overlapping, adjacent rule.
Will a naive solution time out with a million characters?+
Not if you're careful. Since short_s is under 10 characters, comparing at every index costs roughly 10 operations per position. That's about ten million operations total, which is fine. Avoid repeated string concatenation or rebuilding strings inside the loop.
What edge cases should I test?+
Empty short_s, empty long_s, short_s longer than long_s, no occurrence at all, and overlapping patterns like AA in AAA. Also test a run at the very end of long_s so your bounds check doesn't skip it.
How do I prepare for this in 48 hours?+
Write it once from scratch in your language, using index slicing or startswith. Then test the two given examples plus an overlap case. Spend the rest of your time on general string scanning problems so the loop bounds feel automatic.