Count Substrings with Only One Distinct Letter
A easy-tier problem at 81% community acceptance, tagged with Math, String. Reported in interviews at Virtu Financial and 0 others.
You're staring at a string. The problem asks: count all substrings where every character is the same. It's on Virtu Financial's assessment and has an 80% acceptance rate, which means most people pass it, but a handful blank because they don't see the math hiding inside. The trick isn't string manipulation. It's combinatorics. If you hit this live and freeze on the obvious loop, StealthCoder surfaces the formula in seconds so you move on.
Companies that ask "Count Substrings with Only One Distinct Letter"
Count Substrings with Only One Distinct Letter 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 StealthCoderThe naive approach iterates through every possible substring and checks if each one has only one distinct letter. You'll pass most test cases, but it's O(n^2) or worse. The real pattern: find each contiguous block of identical characters, then count substrings within that block using math. A run of length n contains n(n+1)/2 substrings where every character matches. Once you spot that insight, the code becomes linear and obvious. Most candidates don't see it because they jump straight to substring enumeration. If you blank on the combinatorial formula during your assessment, StealthCoder computes it invisibly and hands you the solution.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Substrings with Only One Distinct Letter 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. 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.
Count Substrings with Only One Distinct Letter interview FAQ
How hard is this really for an EASY problem?+
It's genuinely easier than the acceptance rate suggests once you spot the math. The barrier is seeing that you don't iterate substrings at all. You count them. Most who struggle are stuck in substring-loop mode and don't pivot to the combinatorial trick fast enough.
Is Virtu Financial still asking this?+
This problem is on record with Virtu Financial. Whether it shows up in your specific round is unpredictable, but if it does and you freeze on the formula, you need a fast way to unblock. That's what StealthCoder is for.
What's the core pattern I should drill?+
Find runs of identical characters. For each run of length n, the count of valid substrings is n(n+1)/2. Sum across all runs. That's it. Everything else is implementation detail.
Does this test String or Math harder?+
Both. You need to parse the string into runs (String topic), then apply the formula (Math topic). Most candidates nail the string part and trip on the combinatorial count. Knowing both angles matters here.
What if I just brute force it during the OA?+
You'll pass the small test cases. Larger inputs might timeout, depending on constraints. The formula is fast enough to never worry about time. If you're unsure mid-assessment, brute force buys you points while StealthCoder gives you the optimized path.
Want the actual problem statement? View "Count Substrings with Only One Distinct Letter" on LeetCode →