Longest Same-Character Substring
Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Capital One reported this one in May 2026, and the detail that matters is the tie-break: if several runs share the max length, you return the rightmost. The task is to find the longest run of one repeated character, then return that character glued to its count, like "c3". It's a single pass over a string of at most 100 characters. If your OA invite lands in the next day or two, this is the kind of problem you shouldn't lose sleep over. StealthCoder sits invisible on your screen as a safety net if you blank on the details mid-assessment.
The problem
You are given a string source consisting of lowercase English letters. Find the longest contiguous substring consisting of the same character. If several substrings of the same maximum length meet this condition, choose the rightmost one. Return a string consisting of the selected character concatenated with its number of occurrences in the longest contiguous substring, which is the length of that substring. A solution with time complexity no worse than O(source.length^3) will fit within the execution time limit. Function longestSameCharacterSubstring(source: String) → String Examples Example 1 source = "bbacccdbbab" return = "c3" There are two contiguous substrings consisting of a, and both have length 1. There are three contiguous substrings consisting of b; two have length 2 and one has length 1. There is one contiguous substring consisting of c, and it has length 3. It is the longest contiguous substring, so the answer is c3. Example 2 source = "bbaacaa" return = "a2" There are three different contiguous substrings with length 2. The rightmost one is the final aa, so the answer is a2. Constraints 1 <= source.length <= 100 source contains only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The hinted pattern says dynamic programming, but you don't need a table. Walk the string once and track the current run length. If the current character equals the previous one, increment the run. Otherwise reset it to 1. After each step, compare the run to your best length. The trick is the comparison operator. Use >= instead of >, so a later run of equal length overwrites the earlier one. That gives you the rightmost winner for free. Example 2, "bbaacaa", is the test: with > you'd return b2, but the answer is a2. Another pitfall is the output format. Convert the length to a string and concatenate it to the character. Single-character input like "z" should return "z1". The constraints are tiny, so even the brute force passes, but the linear scan is cleaner and easier to get right under pressure. If you freeze on the tie-break, StealthCoder can hand you the working loop live.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Longest Same-Character Substring 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as consecutive characters. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Capital One's OA.
Capital One reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Same-Character Substring FAQ
How hard is the Capital One longest same-character substring problem really?+
Easy. It's a single linear scan with a running counter. The only things that trip people up are the rightmost tie-break and the output format. If you can write a loop that compares adjacent characters, you can solve this in ten minutes.
What's the trick to getting the rightmost substring?+
Update your best answer whenever the current run length is greater than or equal to the best length, not strictly greater. Because you scan left to right, a later run of equal length replaces the earlier one. That handles every tie automatically.
Do I need dynamic programming for this?+
No. You can think of it as a DP where run[i] depends on run[i-1], but you only need one variable, not an array. Keep the current run length and the best so far. That's O(n) time and O(1) space.
What edge cases should I test before submitting?+
Test a single character like "z", which should give "z1". Test a string with all the same character, and one where every character differs, where the rightmost character wins with count 1. Also run the "bbaacaa" example to confirm the tie-break returns a2.
How do I prepare for this in 48 hours?+
Write the scan from scratch twice without looking. Practice run-length style problems on strings and focus on off-by-one handling at the end of the string. Make sure your final comparison happens on every iteration, not only when a run breaks, so the last run is never missed.