Skip to main content

Subtract Product and Sum

EasyMath

Description

Given an integer number n, return the difference between the product of its digits and the sum of its digits. For example, for 234: (2*3*4) - (2+3+4) = 24 - 9 = 15.

Examples

Input:n = 234
Output:15
Explanation:

2*3*4 - (2+3+4) = 24-9 = 15.

Input:n = 123
Output:0
Explanation:

Product of digits: 1 × 2 × 3 = 6. Sum of digits: 1 + 2 + 3 = 6. Result: 6 - 6 = 0

Input:n = 4421
Output:21
Explanation:

Product of digits: 4 × 4 × 2 × 1 = 32. Sum of digits: 4 + 4 + 2 + 1 = 11. Result: 32 - 11 = 21

Constraints

  • 1 ≤ n ≤ 10⁵

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.