Back to problems Sign in to unlock
Leetcode
Easy
Math
Number Theory
Simulation
Subtract the Product and Sum of Digits of an Integer
Compute the difference between the product of an integer's digits and the sum of its digits.
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Subtract Product and Sum of Digits
gfgProblem Statement
Given a positive integer , consider the digits of individually. Compute:
- the product of all digits
- the sum of all digits
Return the value of product - sum.
The task is purely about digit-by-digit processing and simple arithmetic.
Input Format
- A single integer .
- You may assume is positive.
Output Format
- Return an integer representing the product of the digits of minus the sum of the digits of .
Constraints
- Digits are processed in base 10
- The exact upper bound is not required for practice purposes
Examples
Sample cases returned by the problem API.
Example 1
Input
n = 234
Output
15
Explanation
Digits are 2, 3, and 4. Product = 2 × 3 × 4 = 24. Sum = 2 + 3 + 4 = 9. Difference = 24 - 9 = 15.
Example 2
Input
n = 4421
Output
21
Explanation
Digits are 4, 4, 2, and 1. Product = 32. Sum = 11. Difference = 32 - 11 = 21.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.