Competitive ProgrammingEasy

Non decreasing numbers with n digits

Detailed guide and Python implementation for the 'Non decreasing numbers with n digits' problem.

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?
Consider using Dynamic Programming-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.