Reported September 2026
Hudson River Tradingmath

Product Minus Sum of Digits

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 reportedly served this one in September 2026, and the opening angle is the input size. n tops out at 10^9, so there's nothing to brute force. It's a ten-digit loop at most. The question is whether you rush it and flip the subtraction or botch a zero digit. It's a plain math and digit-extraction problem: peel digits off, multiply, add, subtract. If your head goes blank under the timer, StealthCoder runs invisibly during the live OA and gives you the solution as a safety net. Don't overthink it. Read the order carefully and write it clean.

The problem

Given a positive integer number n, your task is to calculate the difference between the product of its digits and the sum of its digits.
Note: The order matters; the answer should be of the form product - sum (and not sum - product).

Function
solution(n: int) → int

Examples
Example 1
n = 123456
return = 699
For n = 123456, the output should be solution(n) = 699.
The product of the digits is equal to 1 * 2 * 3 * 4 * 5 * 6 = 720.
The sum of the digits is equal to 1 + 2 + 3 + 4 + 5 + 6 = 21.
So the final answer is 720 - 21 = 699.
Example 2
n = 1010
return = -2
For n = 1010, the output should be solution(n) = -2.
The multiplication of the digits is equal to 1 * 0 * 1 * 0 = 0.
The sum of the digits is equal to 1 + 0 + 1 + 0 = 2.
So the final answer is 0 - 2 = -2.

Constraints
Input/Output: [execution time limit] 4 seconds (py3)
[memory limit] 1 GB
[input] integer n, A positive integer.
Guaranteed constraints: 1 ≤ n ≤ 10^9.
[output] integer

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is digit extraction with modulo and integer division. Start with product = 1 and sum = 0. While n > 0, take d = n % 10, multiply it into product, add it to sum, then n //= 10. Return product - sum. Since n is at most 10^9, you handle at most 10 digits, so it's effectively constant time. The pitfalls are small but real. Initializing product to 0 makes every answer wrong. Returning sum - product flips the sign. A zero digit zeroes the product, which is correct, as Example 2 shows with -2. Don't convert to a string unless you want to, but it works either way. Test both examples by hand before submitting. If you freeze on a trivial detail mid-assessment, StealthCoder is the hedge that keeps you moving without the proctor seeing anything.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Product Minus Sum of Digits 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as subtract the product and sum of digits of an integer. If you have time before the OA, drill that.

⏵ 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 passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Product Minus Sum of Digits FAQ

How hard is Product Minus Sum of Digits really?+

It's easy. One loop over the digits, with at most 10 of them since n is capped at 10^9. The only ways to lose are initializing the product wrong or subtracting in the wrong order. Hudson River Trading reportedly asked it in September 2026, so expect speed and accuracy to matter more than cleverness.

What's the trick to solving it?+

Use n % 10 to grab the last digit and n // 10 to drop it. Keep a running product starting at 1 and a running sum starting at 0. When the loop ends, return product - sum. That's the whole algorithm.

Does a zero digit break anything?+

No. A zero makes the product zero, which is the intended behavior. Example 2 with n = 1010 returns 0 - 2 = -2. Just don't special-case it or skip zero digits, because the sum still needs them, even though they add nothing.

Should I use string conversion or modulo math?+

Either passes at this input size. Modulo is cleaner and avoids type conversions. String conversion lets you iterate over characters and cast each to int. Pick whichever you can write without bugs. Both run in effectively constant time for up to 10 digits.

How do I prepare for this in 48 hours?+

Write the digit loop from memory twice. Run both examples by hand, including the 1010 case. Then spend the remaining time on other easy math and array warmups, since an OA usually has harder problems alongside this one. Know the pattern cold so you don't burn time on the simple one.

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