 O(N) Solution | Easy explanation
IntuitionThe sum of all digits (modulo 10) should be zero for the number to have digits satisfying the condition.This ensures that the number retains its origin
# Intuition
The sum of all digits (modulo 10) should be zero for the number to have digits satisfying the condition.This ensures that the number retains its original properties when considering mod constraints.


# Complexity
- Time complexity:O(N)

- Space complexity: (1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    bool hasSameDigits(string number) {
        string original = number;
        int length = number.size();
        int lastIndex = length - 2;
        int sumFirstPattern = 0, sumSecondPattern = 0;

        for (int i = 0; i <= lastIndex; ++i) {
            int patternMod2 = computeCombinationMod(lastIndex, i, 2);
            int patternMod5 = computeCombinationMod(lastIndex, i, 5);
            int multiplier = getMultiplier(patternMod2, patternMod5);

            sumFirstPattern = (sumFirstPattern + multiplier * (number[i] - '0')) % 10;
            sumSecondPattern = (sumSecondPattern + multiplier * (number[i + 1] - '0')) % 10;
        }

        return sumFirstPattern == sumSecondPattern;
    }

private:
    int computeFactorialMod(int num, int r, int mod) {
        if (r > num) return 0;
        if (mod == 2) {
            return ((r & ~num) == 0) ? 1 : 0;
        } else {
            int factorial[5], modularInverse[5];
            factorial[0] = 1;
            
            for (int i = 1; i < 5; ++i) {
                factorial[i] = (factorial[i - 1] * i) % 5;
            }
            
            for (int i = 0; i < 5; ++i) {
                modularInverse[i] = computeModularInverse(factorial[i], 3, 5);
            }

            return ((factorial[num] * modularInverse[r]) % 5 * modularInverse[num - r]) % 5;
        }
    }

    int computeCombinationMod(int num, int r, int mod) {
        int result = 1;
        while (num || r) {
            int numMod = num % mod, rMod = r % mod;
            if (rMod > numMod) return 0;
            result = (result * computeFactorialMod(numMod, rMod, mod)) % mod;
            num /= mod;
            r /= mod;
        }
        return result;
    }

    int getMultiplier(int mod2, int mod5) {
        for (int i = 0; i < 10; ++i) {
            if (i % 2 == mod2 && i % 5 == mod5) return i;
        }
        return 0;
    }

    int computeModularInverse(int base, int exponent, int mod) {
        int result = 1;
        while (exponent) {
            if (exponent & 1) result = (result * base) % mod;
            base = (base * base) % mod;
            exponent /= 2;
        }
        return result;
    }

    bool isPalindrome(string str) {
        int left = 0, right = str.size() - 1;
        while (left < right) {
            if (str[left++] != str[right--]) return false;
        }
        return true;
    }

    vector<int> sieve(int maxLimit) {
        vector<int> isPrime(maxLimit + 1, 1);
        isPrime[0] = isPrime[1] = 0;
        for (int i = 2; i <= maxLimit; ++i) {
            if (isPrime[i]) {
                for (int j = i * i; j <= maxLimit; j += i) 
                    isPrime[j] = 0;
            }
        }
        vector<int> primes;
        for (int i = 2; i <= maxLimit; ++i) {
            if (isPrime[i]) primes.push_back(i);
        }
        return primes;
    }

    int factorialMod(int num) {  
        int result = 1;
        for (int i = 2; i <= num; ++i) 
            result = (1LL * result * i) % 1000000007;
        return result;
    }

    int modularExponentiation(long long base, long long exponent, long long mod) {  
        long long result = 1;
        while (exponent) {
            if (exponent & 1) result = (result * base) % mod;
            base = (base * base) % mod;
            exponent >>= 1;
        }
        return result;
    }

    long long modularInverse(long long num, long long mod) {  
        return modularExponentiation(num, mod - 2, mod);
    }
};

```
['C++']