Product Minus Sum of Digits
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The TikTok OA reported in August 2026 hands you a problem where the statement itself spells out the order: product minus sum, not sum minus product. That's the one detail people flip when they're nervous. It's a digit-extraction problem, pure math with a loop, and it's about as easy as OA questions get. If you blank on the syntax under pressure, StealthCoder runs invisibly on your desktop as a safety net. Most candidates won't need it here, but a clean pass on the easy question buys you time for the harder ones.
The problem
Given a positive integer n, calculate the difference between the product of its digits and the sum of its digits. The order matters: return product - sum, not sum - product. Function subtractProductAndSum(n: int) → int Examples Example 1 n = 123456 return = 699 The product of the digits is 1 * 2 * 3 * 4 * 5 * 6 = 720, and their sum is 1 + 2 + 3 + 4 + 5 + 6 = 21. Therefore, the result is 720 - 21 = 699. Example 2 n = 1010 return = -2 The product of the digits is 1 * 0 * 1 * 0 = 0, and their sum is 1 + 0 + 1 + 0 = 2. Therefore, the result is 0 - 2 = -2. Constraints n is a positive integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is peeling digits off with n % 10 and n // 10 until n hits zero. Keep two accumulators. Start the product at 1 and the sum at 0. Multiply and add each digit as you go, then return product - sum. The common pitfall is starting the product at 0, which wipes out every answer. The second is the subtraction order, which the TikTok statement explicitly warns about. Example 2 shows zeros collapsing the product to 0, so 1010 gives -2. Don't convert to a string unless you want to; the arithmetic version is just as short and avoids casting mistakes. Time is O(log n), space is O(1). If the live OA rattles you and the loop won't come together, StealthCoder is the hedge that gets you the working version fast.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
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. 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 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 TikTok's OA.
TikTok 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.
Product Minus Sum of Digits FAQ
How hard is the TikTok Product Minus Sum of Digits problem really?+
It's easy. One loop, two variables, no tricky data structures. The only way to fail is a silly bug: wrong initial product value, or subtracting in the wrong order. Write it, run both examples, and move on to the next question.
What's the trick to solving it?+
Extract digits with n % 10, then shrink n with integer division by 10. Track a running product starting at 1 and a running sum starting at 0. When n reaches 0, return product minus sum. That's the whole solution.
Should I use string conversion or math?+
Either works. Converting to a string and iterating characters is readable, but you need to cast each character back to an int. The modulo approach avoids that and uses constant space. Pick whichever you can write without bugs under pressure.
What edge cases should I test?+
Test a single digit like 5, where product and sum are equal so the answer is 0. Test a number with zeros like 1010, which gives -2 because the product collapses to 0. Also check that your product starts at 1, not 0.
How do I prepare for this in 48 hours?+
Don't spend long on this one. Write the modulo loop once from memory and run both examples. Then spend your remaining time on medium problems in arrays, hash tables, and strings, since the easy question is rarely what separates candidates.