Product of Digits Minus Sum
Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Capital One reportedly put this one in front of candidates in August 2026, and the input size is the first thing to check. n tops out at 2,147,483,647, so it has at most 10 digits. Nothing here needs cleverness or optimization. It's a digit-extraction warm-up, and the only real risk is rushing and flipping the subtraction order. If you blank on the loop, StealthCoder is the safety net running invisibly during the live OA. Most people won't need it for this one, but it's nice to know it's there.
The problem
Given a positive integer n, return the product of its decimal digits minus the sum of its decimal digits. Compute product - sum in that order. Function subtractProductAndSum(n: int) → int Examples Example 1 n = 123456 return = 699 The digit product is 1 * 2 * 3 * 4 * 5 * 6 = 720, while the digit sum is 1 + 2 + 3 + 4 + 5 + 6 = 21. Therefore, return 720 - 21 = 699. Example 2 n = 1010 return = -2 The zero digits make the product 0, and the digit sum is 2. Therefore, return 0 - 2 = -2. Constraints 1 <= n <= 2,147,483,647.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there is no trick. Peel digits off with n % 10 and n // 10 in a loop, keep a running product starting at 1 and a running sum starting at 0, then return product - sum. Ten digits means constant time, so brute force isn't even a concept here. The common pitfalls are small. Starting the product at 0 zeroes everything out. Subtracting in the wrong order gives you the negative of the answer. Forgetting that a zero digit collapses the product, which Example 2 (1010 returns -2) shows on purpose. Converting to a string works too, but the modulo loop is cleaner and avoids type juggling. Test the single-digit case: n = 5 gives 5 - 5 = 0. If the assessment has harder problems alongside this, StealthCoder is the hedge for those, since it reads the screen and hands you a solution if you freeze.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Product of Digits Minus Sum 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
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.
You've seen the question.
Make sure you actually pass Capital One's OA.
Capital One reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Product of Digits Minus Sum FAQ
How hard is the Capital One Product of Digits Minus Sum problem really?+
It's easy. You extract each digit, multiply them, add them, and subtract. There's no data structure and no algorithm choice to agonize over. The only way to miss it is a sloppy initialization or reversing the subtraction. Treat it as a speed and accuracy check.
What's the trick to solving it?+
Use a while loop with n % 10 to grab the last digit and n // 10 to drop it. Start product at 1 and sum at 0. Return product - sum at the end. That's the whole solution, and it runs in time proportional to the digit count.
Should I convert n to a string or use modulo?+
Either works. Modulo avoids conversion and is the more standard approach. A string lets you iterate characters and cast each to an int. Pick whichever you can write without bugs under pressure. Both are fine for a number with at most 10 digits.
What edge cases should I test?+
Test a single digit like 5, which returns 0. Test a number with a zero digit like 1010, which should return -2 because the product collapses to 0. Also test the max value 2147483647 to confirm the product doesn't overflow in your language of choice.
How do I prepare for this in 48 hours?+
Write the digit loop from memory twice, once with modulo and once with a string. Run the two examples, 123456 giving 699 and 1010 giving -2. Then spend your remaining time on harder patterns, since this problem will take a few minutes at most.