Simple || Digit DP || Bitmasking
IntuitionApproachComplexity

Time complexity:
O(k∗2∗1024∗2)   where k represent the number of Digit in n


Space complexity:
O(k∗2∗1024∗2)   where k represent t
# Intuition
    Modified the standard Digit DP approach

# Approach
    Started masking digits after occurance of a non zero digit 
    i.e. skipping leading zeros as they can repeat multiple times

# Complexity
- Time complexity:
O(k∗2∗1024∗2)   where k represent the number of Digit in n

- Space complexity:
O(k∗2∗1024∗2)   where k represent the number of Digit in n

# Code
```cpp []
class Solution {
public:
    int dp[11][2][1024][2];
    int f(string& num, int n, bool tight, int mask, bool started) {     //started rep leading zeroes over or not
        if (n == 0) return 1;   
        if (dp[n][tight][mask][started] != -1)    return dp[n][tight][mask][started];

        int ub = tight ? (num[num.size() - n] - '0') : 9;
        int ans = 0;
        for (int dig = 0; dig <= ub; dig++){
            bool newStrt=started|(dig!=0);        //check did first non 0 come?
            int masked=mask;
            if(newStrt){                          //newStrt becomes 1 then we can start masking
                if (mask & (1<<dig)) continue;    //digit used earlier
                masked|=(1<<dig);
            }
            ans+=f(num,n-1,tight&(dig==ub),masked,newStrt);
        }
        return dp[n][tight][mask][started] = ans;
    }

    int numDupDigitsAtMostN(int n) {
        memset(dp,-1,sizeof dp);
        string num = to_string(n);
        return n - f(num,num.length(),1,0,0) +1;
    }
};
```
['Math', 'Dynamic Programming', 'C++']