Subtract the Product and Sum of Digits of an Integer

Given an integer n, return the product of its digits minus the sum of its digits.

30:00

Subtract the Product and Sum of Digits of an Integer
easy
Free written solution
Topics
Companies

Given an integer n, return the product of its digits minus the sum of its digits.

Example 1:
Input: {"n":234}
Output: 15
Constraints:
  • 1≤n≤1051 \leq n \leq 10^5

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":234}

Start product at 1 and total at 0, the values that leave a first digit unchanged when you multiply or add it.

n = 234, digits peeled from the right

2

10^2

3

10^1

4

10^0

two running totals

product

1

= 1

sum

0

= 0

answer

1 − 0 = ?
Variables
VariableValue
n234
product1
total0
DepthFunction Call
Stack empty
0/16