Reported September 2024
Hudson River Tradingcounting

Count Fancy Numbers

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

Hudson River Trading sent you Count Fancy Numbers in September 2024, and you've got maybe two days. This is a counting problem that looks straightforward until you realize the constraint. You need to count integers in a range that satisfy some property. The trick isn't brute force. It's recognizing the mathematical structure so you can compute the answer in logarithmic time instead of iterating. StealthCoder sits ready if the pattern doesn't click during the live OA.

Pattern and pitfall

Count Fancy Numbers is a digit DP or mathematical counting problem. The 'fancy' property is usually defined by digit constraints or a specific divisibility/parity rule. The naive approach iterates every number in the range and checks each one. That fails on large ranges. The real solution uses prefix counting: build a function that counts valid numbers from 0 to N, then answer(L, R) = count(R) - count(L-1). If the property involves digit sums, digit patterns, or modular arithmetic, dynamic programming over digit positions is standard. Recognize that you're not summing a large dataset; you're exploiting mathematical closure to skip impossible branches. StealthCoder catches the edge cases and the DP state definition if you freeze mid-interview.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Count Fancy Numbers 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Fancy Numbers FAQ

What does 'fancy' actually mean here?+

Without the full problem text, 'fancy' likely refers to digits or a mathematical property (divisibility, digit sum parity, palindrome structure, etc.). Hudson River Trading problems often hide the rule in the problem statement wording. Read it twice. The property is the entire puzzle.

Is this a brute force range, or do I need math?+

If the range is N < 10^6, brute force might pass. If N > 10^9, you need digit DP or a closed-form formula. Hudson River Trading typically expects the optimized approach. Assume you need something faster than O(N) iteration.

How do I even structure digit DP for this?+

State: dp[position][constraint_flags]. Iterate left-to-right through digits, tracking whether you're still bounded by the input number. At each digit, count all valid choices and recurse. Base case: reached the end. This pattern applies to almost all 'count numbers with property X' problems.

What's the most common mistake?+

Off-by-one errors in the range calculation (forgetting to handle L-1 correctly) and not considering leading zeros. Also, misunderstanding when a digit choice violates the 'fancy' constraint. Re-read the property definition carefully before coding.

Can I solve this in 30 minutes?+

If you recognize the pattern immediately, yes. If you don't, you'll spin on brute force and run out of time. The key is spotting that you need digit DP or math, not simulation. That click usually comes in the first 10 minutes or not at all.

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