
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count N-Digit Integers with Strictly Increasing Digits in Python
Suppose we have a number n, we have to find the number of n-digit positive integers such that the digits are in strictly increasing order.
So, if the input is like n = 3, then the output will be 84, as numbers are 123, 124, 125, ..., 678,789
To solve this, we will follow these steps −
-
if n < 9 is non-zero, then
return Combination (9Cn)
-
otherwise,
return 0
Let us see the following implementation to get better understanding −
Example
from math import factorial as f class Solution: def solve(self, n): if n < 9: return f(9) / f(n) / f(9 - n) else: return 0 ob = Solution() print(ob.solve(3))
Input
3
Output
84
Advertisements