Reported March 2026
Adobesliding window

Count Distinct Fixed-Length Substrings

Reported by candidates from Adobe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Adobe OA. Under 2s to a working solution.
Founder's read

The Adobe OA reported in March 2026 hands you a string up to 10^5 characters and asks how many distinct length-k substrings it has. Looks like a freebie. It isn't, because the obvious approach dies on the input size. This is a sliding window plus hashing problem, and the trick is not storing the substrings themselves. You have the pattern now. If you blank on the rolling hash during the live assessment, StealthCoder sits invisibly on your screen and gives you a working solution in real time.

The problem

Given a lowercase string text and an integer k, consider every contiguous substring of text whose length is exactly k.
Return the number of distinct substring values among those windows. Equal text appearing at different positions counts once.

Function
countDistinctSubstrings(text: String, k: int) → int

Examples
Example 1
text = "ababa"
k = 2
return = 2
The length-2 windows are ab, ba, ab, and ba. The distinct values are ab and ba.
Example 2
text = "aaaa"
k = 2
return = 1
Every length-2 window is aa, so there is one distinct value.
Example 3
text = "abc"
k = 1
return = 3
The one-character windows are a, b, and c, all distinct.

Constraints
1 <= text.length <= 10^5.
text contains only lowercase English letters.
1 <= k <= text.length.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Brute force slices every window and drops it into a set. With n up to 10^5 and k up to n, each slice costs O(k), so you're looking at O(n*k) time and memory. At k near n/2 that's billions of character operations. The fix is a rolling hash. Compute the hash of the first window, then slide: subtract the outgoing character's contribution, multiply by the base, add the incoming one, all mod a large prime. Put the hashes in a set and return its size. O(n) total. The pitfall is collisions. Use a big modulus or double hash, and watch the power term base^(k-1) when removing the leading character. Negative mod results are the other classic bug. A suffix automaton or suffix array also works, but it's overkill here. If the rolling hash math slips under pressure, StealthCoder is your hedge during the live OA.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Count Distinct Fixed-Length Substrings 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Adobe's OA.

Adobe reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Distinct Fixed-Length Substrings FAQ

What's the trick in the Adobe distinct substrings problem?+

Don't store the substrings. Use a rolling hash so each window's hash updates in O(1) as you slide. Collect the hashes in a set and return its size. That turns O(n*k) into O(n), which is what the 10^5 limit demands.

Will a plain set of substrings pass?+

Probably not on large tests. Each slice copies up to k characters, so total work and memory grow like n*k. Small examples pass, but with n = 10^5 and a mid-sized k you'll hit a time or memory failure. Hash the windows instead.

How do I avoid hash collisions?+

Pick a large prime modulus like 10^9+7 and a base above 26, such as 31 or 131. For extra safety, run two moduli and store the pair as the key. Single-hash collisions are rare but possible, and a double hash makes them negligible for 10^5 characters.

What edge cases should I test?+

Test k equal to text length, which always returns 1. Test k = 1, which returns the count of distinct letters. Test a string of one repeated letter, which returns 1. Also check that your mod subtraction never goes negative when removing the outgoing character.

How do I prepare for this in 48 hours?+

Write a rolling hash by hand twice, once for a fixed window and once for Rabin-Karp matching. Get the remove-leading-character step right, including the precomputed power. Then run your code on the three examples and a 10^5 stress input to confirm it's linear.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Adobe.

OA at Adobe?
Invisible during screen share
Get it