Problem · Math
Product Minus Sum of Digits
Learn this problemProblem statement
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) → intExamples
Example 1
n = 123456return = 699The 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 = 1010return = -2The 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
nis a positive integer.
More Tiktok problems
- Concatenate Digit-wise SumsOA · Seen Aug 2026
- Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
- Count House Segments After DestructionOA · Seen Aug 2026
- Debugger Breakpoint ActionsOA · Seen Aug 2026
- Distribution Center Package AllocationOA · Seen Aug 2026
- Find All Local PeaksOA · Seen Aug 2026
- Minimum Height Difference Between Distant PeaksOA · Seen Aug 2026
- Minimum Operations for Stepwise StructuresOA · Seen Aug 2026