Digit Product Minus Digit Sum

Quick Overview

Digit Product Minus Digit Sum. For positive integer n, multiply its decimal digits and separately add them.

Digit Product Minus Digit Sum

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem For positive integer n, multiply its decimal digits and separately add them. Return the product minus the sum. ```cpp class Solution { public: int subtractProductAndSum(int n); }; ``` ### Examples **Example 1:** ```text Input: n = 125 Output: 2 Explanation: The product is1*2*5=10 and the sum is1+2+5=8. ``` **Example 2:** ```text Input: n = 101 Output: -2 Explanation: A zero makes the product0, while the digit sum is2. ``` ### Constraints - n is an integer in `[1,100000]`. ### Contract considerations The input range excludes zero and negative integers. ```hint Read the boundary condition Are digits interpreted in decimal, and which subtraction order does the contract require? ``` ### Boundary reminders The input range excludes zero and negative integers.

Overview: Digit Product Minus Digit Sum. For positive integer n, multiply its decimal digits and separately add them.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

For positive integer n, multiply its decimal digits and separately add them. Return the product minus the sum.

class Solution {
public:
    int subtractProductAndSum(int n);
};

Examples

Example 1:

Input: n = 125
Output: 2
Explanation: The product is1*2*5=10 and the sum is1+2+5=8.

Example 2:

Input: n = 101
Output: -2
Explanation: A zero makes the product0, while the digit sum is2.

Constraints

  • n is an integer in [1,100000] .

Contract considerations

The input range excludes zero and negative integers.

Boundary reminders

The input range excludes zero and negative integers.