JuniorMath

Subtract the Product and Sum of Digits of an Integer

Given an integer number n, return the difference between the product of its digits and the sum of its digits.

Example 1
Inputn = 234
Output15
Product of digits is 2 * 3 * 4 = 24, sum of digits is 2 + 3 + 4 = 9, and 24 - 9 = 15.
Example 2
Inputn = 4421
Output21
Product of digits is 4 * 4 * 2 * 1 = 32, sum of digits is 4 + 4 + 2 + 1 = 11, and 32 - 11 = 21.

Constraints

  • 1 <= n <= 10^5

Asked at 5 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate