Back to Practice Dashboard
Competitive ProgrammingEasy
Non decreasing numbers with n digits
Learn how to solve the 'Non decreasing numbers with n digits' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function count_non_decreasing(n) that returns the count of non-decreasing numbers with n digits. A number is non-decreasing if every digit is greater than or equal to the digit to its left. Leading zeros are allowed (e.g. 012 is non-decreasing).
Constraints
- •1 <= n <= 20
Examples
Example 1
Input
count_non_decreasing(1)
Output
10
Explanation
All single digit numbers (0 to 9) are non-decreasing.
Example 2
Input
count_non_decreasing(2)
Output
55
Explanation
There are 55 non-decreasing numbers of 2 digits (like 00, 01, ..., 11, 12, ..., 99).
Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.