Problem · Math

Product of Digits Minus Sum

Learn this problem
EasyCapital One logoCapital OneINTERNOA

Problem 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) → int

Examples

Example 1

n = 123456return = 699

The 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 = -2

The zero digits make the product 0, and the digit sum is 2. Therefore, return 0 - 2 = -2.

Constraints

  • 1 <= n <= 2,147,483,647.

More Capital One problems

drafts saved locally
public int subtractProductAndSum(int n) {
    // Write your code here.
}
n123456
expected699
checking account