FastPrepProduct Minus Sum of Digits
Problems/Product Minus Sum of Digits

Product Minus Sum of Digits

TikTok logoTikTok● EasyINTERNNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits a numeric upper bound. The judged core task matches the visible source at about 99%.

Given a positive integer n, calculate the difference between the product of its digits and the sum of its digits.

The order matters: return product - sum, not sum - product.

Function

subtractProductAndSum(n: int) → int

Examples

Example 1

n = 123456return = 699

The product of the digits is 1 * 2 * 3 * 4 * 5 * 6 = 720, and their sum is 1 + 2 + 3 + 4 + 5 + 6 = 21. Therefore, the result is 720 - 21 = 699.

Example 2

n = 1010return = -2

The product of the digits is 1 * 0 * 1 * 0 = 0, and their sum is 1 + 0 + 1 + 0 = 2. Therefore, the result is 0 - 2 = -2.

Constraints

  • n is a positive integer.

More TikTok problems

  • Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
  • Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
All TikTok interview questionsSee TikTok hiring insights
Saved
class Solution {
    public int subtractProductAndSum(int n) {
        // Write your code here.
    }

}
Checking account…