If any number is represented in such a way that when we are reading it from left to right each ith Digit is greater or equal than i-1th digit is known as an increasing number. And if digits of any number are decreasing from left to right it’s known as decreasing number.`
Increasing Number ?235668
all the digits from left to right are greater or equal to the previous digit.
Decreasing Number ? 653221
all the digits from left to right are lesser than or equal to the previous digit.
But if the number is neither increasing nor decreasing is Known as Bouncy Number.
523469 -> Some Digits from left to right are decreasing from left to right and some are increasing. So this is the example of Bouncy Number.
The task in this article is to count the total number of Non-Bouncy Numbers below 10k and print the final count in mod(109+7). To do this we will use the Stars and Bars method to calculate the number of non-bouncy numbers in the given range.
Stars and Bars Method:
Stars and Bars method is a technique that is used to deal with combination based problems. These type of problems arises when we want the number of identical groups.
The formula for calculating identical groups:
Where N are the identical objects and M is the container or range.
Input : k = 6 Output : 12951 Input : k = 9 Output : 140906
Below is the implementation:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course