💻⌛EASY SOLUTION🗝️| BEATS 100% ✅⚡| (C++/Java/Python/Javascript)🍨
IntuitionWe are tasked with calculating the difference between the product and the sum of the digits of a number n. The core idea is to extract the digits of th
# **Intuition**  
We are tasked with calculating the difference between the product and the sum of the digits of a number `n`. The core idea is to extract the digits of the number, compute their sum and product simultaneously, and then subtract the sum from the product.

# **Approach**  
1. Initialize two variables: `sum` to 0 (to store the sum of digits) and `product` to 1 (to store the product of digits).
2. Use a loop to iterate through each digit of the number:
   - Extract the last digit of `n` by taking `n % 10`.
   - Add this digit to `sum`.
   - Multiply this digit to `product`.
   - Remove the last digit of `n` by performing integer division `n //= 10`.
3. After processing all digits, return the difference between `product` and `sum`.

# **Complexity**  
- **Time Complexity:**  
  - `O(d)`, where `d` is the number of digits in the number `n`. The loop runs once for each digit.
- **Space Complexity:**  
  - `O(1)`, since we are using a constant amount of space for the sum and product.

# **Code**  

``` C++ []
class Solution {
public:
    int subtractProductAndSum(int n) {
        int sum = 0;
        int product = 1;

        while (n > 0) {
            int digit = n % 10;
            sum += digit;
            product *= digit;
            n /= 10;
        }return product - sum;
    }
};
```

```python []
class Solution:
    def subtractProductAndSum(self, n: int) -> int:
        sum_digits = 0
        product_digits = 1

        while n > 0:
            digit = n % 10
            sum_digits += digit
            product_digits *= digit
            n //= 10

        return product_digits - sum_digits
```

```java []
class Solution {
    public int subtractProductAndSum(int n) {
        int sum = 0;
        int product = 1;

        while (n > 0) {
            int digit = n % 10;
            sum += digit;
            product *= digit;
            n /= 10;
        }return product - sum;
    }
}
```

```javascript []
/**
 * @param {number} n
 * @return {number}
 */
var subtractProductAndSum = function(n) {
    let sum = 0;
    let product = 1;

    while (n > 0) {
        let digit = n % 10;
        sum += digit;
        product *= digit;
        n = Math.floor(n / 10);
    }return product - sum;
};
```
```
✨ AN UPVOTE WILL BE APPRECIATED ^_~ ✨
```
['Python', 'C++', 'Java', 'Python3', 'JavaScript']