Subtract Product and Sum of Digits

EasyMath

Description

Given an integer n, return the product of its digits minus the sum of its digits. If n is negative, treat its digits as |n|.

Examples

Input:n = 234
Output:15
Explanation:

Digits are 2, 3, 4 with product 24 and sum 9, so the answer is 15.

Input:n = 4421
Output:21
Explanation:

Digits are 4, 4, 2, 1 with product 32 and sum 11, so the answer is 21.

Input:n = 0
Output:0
Explanation:

Single digit 0: product = 0, sum = 0, result = 0.

Input:n = 10
Output:-1
Explanation:

Digits are 1, 0 with product 0 and sum 1, so the answer is -1.

Constraints

  • 0 ≤ n ≤ 10⁹

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.