Reported September 2026
Hudson River Tradingstring

Rightmost Longest Character Run

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

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

The mistake that sinks a first attempt on this Hudson River Trading OA, reported in September 2026, is a single character: using > when you should use >=. The task looks trivial. Find the longest run of one repeated letter, and on ties return the rightmost one, formatted as the letter plus its count. Candidates rush it, pass the first example, and fail the tie case in the second. It's a plain linear scan, not real dynamic programming, even though it's tagged that way. If you blank mid-assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the clean loop.

The problem

You are given a string source consisting of lowercase English letters.
Find the longest contiguous substring that consists of the same character. If several such substrings have the same maximum length, choose the rightmost one.
Return a string containing the chosen character followed by the number of times it occurs in that substring.
A solution with time complexity no worse than O(source.length^3) fits within the execution time limit.

Function
solution(source: String) → String

Examples
Example 1
source = "bbacccdbbab"
return = "c3"
The character a appears in two runs of length 1. The character b appears in three runs: two of length 2 and one of length 1. The single c run has length 3, so it is the longest run and the result is "c3".
Example 2
source = "bbaacaa"
return = "a2"
The runs "bb", the first "aa", and the final "aa" all have the maximum length 2. The final "aa" is the rightmost maximum run, so the result is "a2".

Constraints
source consists only of lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is one pass. Walk the string, keep a current run length, and reset it to 1 whenever the character changes. After each step, compare the current run to the best so far. Use >= so a later run of equal length replaces the earlier one. That single operator is what makes the answer the rightmost. The common pitfall is using strict > and returning the leftmost run, which fails example 2, where the answer is a2 and not b2. Other traps are forgetting to update after the final character, and returning the count as a number instead of concatenating it to the letter. Time is O(n), space is O(1), far under the stated O(n^3) allowance. If you freeze, StealthCoder can supply this loop live, but you should know the >= detail cold.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Rightmost Longest Character Run 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 would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Hudson River Trading's OA.

Hudson River Trading reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Rightmost Longest Character Run FAQ

How hard is Rightmost Longest Character Run really?+

Easy. It's one linear pass with a running counter. The only real difficulty is the tie-breaking rule. If you read the rightmost requirement carefully and test example 2, you'll get it right in a few minutes.

What's the trick to getting the rightmost run?+

Update your best answer whenever the current run length is greater than or equal to the best, not just greater. Because you scan left to right, every tie overwrites the earlier run, so the final stored run is the rightmost one.

Do I need dynamic programming for this?+

No. It's tagged that way, but a simple scan with a counter does the job. You don't need a table or memoization. Overbuilding it just adds bugs. Keep two or three variables: current char, current length, best char and length.

What edge cases should I test?+

Test a single-character string, a string where all characters are identical, and one where every run has length 1, which should return the last character with 1. Also test example 2 for ties, and make sure the final run gets compared after the loop ends.

How do I prepare in 48 hours for an OA like this?+

Practice the run-length scan pattern until you can write it without thinking, then rehearse tie-breaking variants: leftmost versus rightmost. Write the function signature, return format, and a few custom tests by hand. Most of the score comes from reading the spec precisely.

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

OA at Hudson River Trading?
Invisible during screen share
Get it