I need to find the number of ways in which one can write a given number in hexadecimal format, where $0$, $1$ and $A$ must appear at least once. Hexadecimal number can have maximum length of the given number.
For example: for $n = 3$, we have 4 possibilities i.e. $10A, 1A0, A01, A10$ (we ignore the leading zero)
Other hexadecimal numbers are allowed. $1A07$ is valid output for $n = 4$.
For $n = 5$, the answer is $10190$. I need to find an answer for $n = 16$.
What is the efficient way to solve this? Is there any algorithm for this?
Compute the total number of strings. Subtract those without $0$, those without $1$, and those without $A$. Use inclusion-exclusion to correct for the ones missing two or three of your characters of interest. You can search the site for many examples.