FastPrepProduct Minus Sum of Digits
Problem · Math

Product Minus Sum of Digits

Learn this problem
EasyHudson River Trading logoHudson River TradingINTERNOA

Problem statement

Given a positive integer number n, your task is to calculate the difference between the product of its digits and the sum of its digits.

Note: The order matters; the answer should be of the form product - sum (and not sum - product).

Function

solution(n: int) → int

Examples

Example 1

n = 123456return = 699

For n = 123456, the output should be solution(n) = 699.

  • The product of the digits is equal to 1 * 2 * 3 * 4 * 5 * 6 = 720.
  • The sum of the digits is equal to 1 + 2 + 3 + 4 + 5 + 6 = 21.

So the final answer is 720 - 21 = 699.

Example 2

n = 1010return = -2

For n = 1010, the output should be solution(n) = -2.

  • The multiplication of the digits is equal to 1 * 0 * 1 * 0 = 0.
  • The sum of the digits is equal to 1 + 0 + 1 + 0 = 2.

So the final answer is 0 - 2 = -2.

Constraints

  • Input/Output: [execution time limit] 4 seconds (py3)
  • [memory limit] 1 GB
  • [input] integer n — A positive integer.
  • Guaranteed constraints: 1 ≤ n ≤ 10^9.
  • [output] integer

More Hudson River Trading problems

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