Problem · Math
Product of Digits Minus Sum
Learn this problemProblem statement
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) → intExamples
Example 1
n = 123456return = 699The 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 = 1010return = -2The zero digits make the product 0, and the digit sum is 2. Therefore, return 0 - 2 = -2.
Constraints
1 <= n <= 2,147,483,647.