MEDIUMasked at 1 company

Find Longest Special Substring That Occurs Thrice II

A medium-tier problem at 38% community acceptance, tagged with Hash Table, String, Binary Search. Reported in interviews at Rubrik and 0 others.

Founder's read

Find Longest Special Substring That Occurs Thrice II is a tricky string problem that weeds out candidates who rush. With a 38% acceptance rate, it shows up in Rubrik assessments and catches people who don't nail the substring-counting logic early. The "special substring" constraint and the "exactly three times" requirement aren't as straightforward as they sound on first read. Most candidates either over-count overlapping matches or miss the binary search optimization that separates AC from TLE. If this lands in your live OA and you haven't drilled the pattern, StealthCoder surfaces a working solution invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
38%

Companies that ask "Find Longest Special Substring That Occurs Thrice II"

If this hits your live OA

Find Longest Special Substring That Occurs Thrice II 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 engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The core trick is recognizing that a "special substring" means consecutive identical characters, which narrows the search space significantly. Candidates often miss that you're not looking for any substring, just runs of the same character, then filtering by length and occurrence count. Many start with a brute-force approach: generate all substrings, count occurrences, track the longest. This works for small inputs but tanks on medium test cases. The real pattern is combining Hash Table and Sliding Window to count substring occurrences efficiently, then Binary Search to find the longest valid length without generating every substring. The gotcha is handling the boundary between single-character repetitions and multi-character ones. People who skip this distinction or don't implement the sliding window correctly get wrong answers or timeouts. StealthCoder becomes your hedge if you hit this during a timed assessment and the indexing logic escapes you.

Pattern tags

The honest play

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

Find Longest Special Substring That Occurs Thrice II 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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Longest Special Substring That Occurs Thrice II interview FAQ

What exactly is a 'special substring' in this problem?+

A special substring is a contiguous sequence of identical characters, like 'aaa' or 'bb'. You're not looking for patterns or substrings with mixed characters. This constraint is the key insight that makes the problem solvable in reasonable time.

Why does the naive approach time out?+

Generating all possible substrings is O(n^2) at minimum, and checking each for valid occurrences adds another factor. With binary search on the length and a counting strategy, you can prune impossible lengths and avoid recalculating overlaps.

How does binary search fit into the solution?+

Binary search on the substring length. If a substring of length L occurs at least three times, any shorter substring of that pattern will too. Search for the longest valid length by partitioning on L and checking feasibility, dropping comparisons from O(n^2) to O(n log n).

Is this problem still asked at companies like Rubrik?+

Yes. Rubrik reports this problem, and at 38% acceptance, it's a meaningful filter in their OA. It's not a super-common leetcode, so prep coverage is lower, which makes it a better discrimination tool for them.

Which topics should I study before attempting this?+

Hash Table for occurrence counting, Sliding Window for substring extraction, and Binary Search for length optimization. Counting is implicit in the hash table. Mastering these four in combination is what cracks this problem.

Want the actual problem statement? View "Find Longest Special Substring That Occurs Thrice II" 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.