Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

A number is non-decreasing if each of its digits is greater than or equal to the previous digit. For example, 223, 4455567, 899, are non-decreasing numbers.

Given an integer **N**, find the total number of non-decreasing numbers that have N digits.

**Example 1:**

**Input:** N = 1
**Output:** 10
**Explaination:** All the single digit numbers
are non-decreasing. So count is 10.

**Example 2:**

**Input:** N = 2
**Output:** 55
**Explaination:** For number starting with 1 there
is 1 decreasing number 10, for number starting
with 2 there are 2 decreasing numbers.
Similarly numbers starting with 3, 4 . . . 9
there are 3, 4 . . . 9 decreasing numbers.
Total 45 decreasing numbers. Total possible
numbers are 10^{2} = 100. So total number of
non-decreasing numbers are 100-45 = 55.

**Your Task:**

You do not need to read input or print anything. Your task is to complete the function **count()** which takes the number N as input parameter and return the total number of non-decreasing numbers.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N ≤ 500

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Total number of non-decreasing numbers with n digits

...