Given an integer N, the task is to find the count of N-digit numbers with all distinct digits.
Input: N = 1
1, 2, 3, 4, 5, 6, 7, 8 and 9 are the 1-digit numbers
with all distinct digits.
Input: N = 3
Approach: If N > 10 i.e. there will be atleast one digit which will be repeating hence for such cases the answer will be 0 else for the values of N = 1, 2, 3, …, 9, a series will be formed as 9, 81, 648, 4536, 27216, 136080, 544320, … whose Nth term will be 9 * 9! / (10 – N)!.
Below is the implementation of the above approach:
Time Complexity: O(n)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Count numbers with exactly K non-zero digits and distinct odd digit sum
- Numbers having Unique (or Distinct) digits
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Count numbers with same first and last digits
- Count of numbers from range [L, R] that end with any of the given digits
- Count of numbers from range [L, R] whose sum of digits is Y
- Count of n digit numbers whose sum of digits equals to given sum
- Count Numbers with N digits which consists of odd number of 0's
- Count Numbers with N digits which consists of even number of 0’s
- Count different numbers possible using all the digits their frequency times
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Count different numbers that can be generated such that there digits sum is equal to 'n'
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.